Question

JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number....

JAVA

Prompt the user for 10 numbers using a while loop. Create an int variable number. You have three additional int variables pos, neg, and zero. Your goal is to determine the number of positive, negative, and zeroes in the list of the ten numbers read in.

Homework Answers

Answer #1

Source Code in text format (See below images of code for indentation):

import java.util.*;

/*class definition*/

public class Main

{

    /*main method*/

    public static void main(String[] args)

    {

        /*Scanner object to read input from the user*/

        Scanner read=new Scanner(System.in);

        /*variables*/

        int number,pos=0,neg=0,zero=0,i=0;

        /*read 10 numbers from user*/

        System.out.println("Enter 10 numbers:");

        while(i<10)

        {

            /*read a number from user*/

            number=read.nextInt();

            /*check for negative*/

            if(number<0)

                neg++;

            /*check for positive*/

            else if(number>0)

                pos++;

            /*zeroes*/

            else

                zero++;

            i++;

        }

        /*print all counts*/

        System.out.println("The number of positive numbers: "+pos);

        System.out.println("The number of negative numbers: "+neg);

        System.out.println("The number of zeros: "+zero);

    }

}

Source Code:

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Write a Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail. Example of the expected output is as follows:
Prompt the user for a positive whole number (call it n) Use a loop to calculate...
Prompt the user for a positive whole number (call it n) Use a loop to calculate the following: Sum: 1+2+...+n Sum of squares: 1^2 + 2^2 + ... + n^2 factorial: 1 x 2 x ... x n Print out the numbers when the loop is done. Do this with a for loop and a while loop. Call the class LoopArithmetic Sample output: The sum from 1 up to 5 is: 15 The sum of squares 1 to 5 is:...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive the amount and declare the variable double amount for scanner Declare variable integer remaining amount which is equal to (int) (amount*100) Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100 Declare: remaining amount %=100 Find the number of quarters: Declare integer variable number of quarters equal to remaining amount divided by 25 Declare:...
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user can type...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
1-Create a week_tuple and assign the days of the week as strings to the week_tuple. b....
1-Create a week_tuple and assign the days of the week as strings to the week_tuple. b. Print out the elements in the week_tuple. 2-a. The following list has been declared as follows: credit_list = [24,3,15] b. Convert the credit_list to a tuple named credit_tuple. c. Print out the elements in the credit_tuple. 3-a. Write an initialize_list_values function that takes in a number for the number of elements in a list and an initial value for each element. The function creates...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also define...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT