Advertisement
newbninja

Question 3

Oct 16th, 2023
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberAnalyzer {
  4.     public static void main(String[] args) {
  5.         // Create a Scanner object to read input from the user
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         // Prompt the user to enter a float value
  9.         System.out.print("Enter a float value: ");
  10.  
  11.         // Read the float value from the user
  12.         float number = scanner.nextFloat();
  13.  
  14.         // Close the Scanner
  15.         scanner.close();
  16.  
  17.         // Check if the entered number is ZERO
  18.         if (number == 0) {
  19.             System.out.println("ZERO");
  20.         }
  21.         // Check if the entered number is positive
  22.         else if (number > 0) {
  23.             // Check if the positive number is less than 1
  24.             if (number < 1) {
  25.                 System.out.println("small positive");
  26.             }
  27.             // Check if the positive number is greater than or equal to 1,000,000
  28.             else if (number >= 1000000) {
  29.                 System.out.println("large positive");
  30.             }
  31.             // If the positive number doesn't meet the above conditions
  32.             else {
  33.                 System.out.println("positive");
  34.             }
  35.         }
  36.         // Check if the entered number is negative
  37.         else {
  38.             // Check if the negative number is greater than -1 (but not equal to 0 or -1)
  39.             if (number > -1) {
  40.                 System.out.println("small negative");
  41.             }
  42.             // Check if the negative number is less than or equal to -1,000,000
  43.             else if (number <= -1000000) {
  44.                 System.out.println("large negative");
  45.             }
  46.             // If the negative number doesn't meet the above conditions
  47.             else {
  48.                 System.out.println("negative");
  49.             }
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement