Write a Java program that reads a floating-point number and prints "zero" if the number is zero. Otherwise, print "positive" or "negative". Add "small" if the absolute value of the number is less than 1, or "large" if it exceeds 1,000,000

Write a Java program that reads a floating-point number and prints "zero" if the number is zero. Otherwise, print "positive" or "negative". Add "small" if the absolute value of the number is less than 1, or "large" if it exceeds 1,000,000.


Solution:


 
package w3;

import java.util.Scanner;

public class EX4 {
  
    public static void main(String[] args) {
      
        Scanner put = new Scanner(System.in);
      
        int num;
        System.out.println("Enter a Number : ");
        num = put.nextInt();
      
        if(num>0) {
            System.out.println("Positive number");
      
        }
        else if(num<0){
            System.out.println("Negative number");
        }
        else{
            System.out.println("Zero");
        }
        if(num<1){
            System.out.println("Small");
        }
        else if(num>1000000){
            System.out.println("large");
        }
      
    }
  
}















Comments

  1. Try this:

    System.out.print("Enter an integer: ");
    float num2 = put.nextFloat();

    if (num2 == 0){
    System.out.println("Zero number");
    }
    else if (num2 < 0){
    System.out.println("Negative number");
    }
    else if (num2 > 0){

    System.out.println("Positive number");

    if(num2 < 1){
    System.out.println("Small");
    }
    else if(num2 > 1000000){
    System.out.println("Large");
    }
    }

    ReplyDelete
  2. num2 is num1 hehe my bad then the last bracket is not included... God Bless.. Lloyd from ABC Dipolog

    ReplyDelete

Post a Comment