Question

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) Inside of that while loop declare selection with if statement which is equal to zero

                  then do the break

7) After that do the addition of variable sum which is sum plus number

  8) In the end print the sum of number when you enter number zero

2) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner)

Steps:

                  1) Declare the variable of outer loop int and assign value of your choice

                  2) Declare while condition which outer variable is less the number of your choice

                  3) Declare variable of inner loop int and assign the value of your choice

                  4) Declare while condition where inner variable is less the number of your choice

                  5) Print the outer and inner value

                  6) Increment inner by 1

                  7) Increment outer by 1


3) Write a java program where you will enter as many numbers as you want and, in the end, when you press zero it will display the largest number.

Steps:

                  1) Create scanner object

                  2) Declare variable number and max;

                  3) Enter the number with prompt system

                  4) Declare number and input statement

                  5) Declare max which is equal to number (in other word any number that you enter is equal to max)

                  6) Declare the while condition where number is not equal to zero

                  7) Inside of that while brace condition declares number and his input statement

                  8) After that create selection if statement where number is greater than max variable

                  9) Declare after that, that variable max is equal to variable number

                  10) In the end show in print the max number

                  Note: basically, after you enter numbers of your choice when you enter zero it should give you the largest number.

Homework Answers

Answer #1

import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner inp=new Scanner(System.in);
       int sum=0;
       while(true){//repeat the loop until 0 is entered
       System.out.println("Enter the number:");
       int number=inp.nextInt();//read number
       if(number==0)//break loop if number is 0
       break;
       sum+=number;//add number to sum
       }
       System.out.println(sum);
   }
}

Screenshots:

The screenshots are attached below for reference.

Please follow them for output.

Note:

Please see that as per the guidelines, we are allowed to answer maximum upto one question posted in a single question.

In case of multiple choice type questions, upto 4 questions can be answered.

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 nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
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...
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
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...
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.
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT