Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Fix Java Code for Developing Product Calculator?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 19
    Answer it

    Write a program requesting a number (n), then ask n numbers more and print their product (use "for"!). The requested "n" number must be integer and positive. (The multiplied numbers must not be positive!)

     

    The result should be like these:

     

    Sample 1.)

    Product calculator.
    Enter a number: 4
    1. number: 1
    2. number: 2
    3. number: 5
    4. number: 2
    Product of entered numbers is 20

     

    Sample 2.)

    Product calculator.
    Enter a number: -10
    'n' value must be positive.

     

    My program:
     

            Scanner sc = new Scanner(System.in);
            int n;
            int enter;
    
            System.out.println("Product calculator.\n" + "Enter a number");
            n = sc.nextInt();
    
            if (n <= 0) {
                System.out.print("'n' value must be positive");
            } else {
                for (int i = 1; i <= n; i++) {
    
                    System.out.print(i + ". number: " + " ");
                    enter= sc.nextInt();
                }
                System.out.print("Product of numbers is ");
            }
    
        }
    
    }

     

    Please help me to correct and finalize this program.

     

    Thank you very much in advance.

     

    Cheers,

    Benjamin

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: