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
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...
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...
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...
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...
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...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
In this Java programming assignment, you will practice using selection statements to determine whether a given...
In this Java programming assignment, you will practice using selection statements to determine whether a given year in the past or future qualifies as a “Leap Year”. I. Design a class called LeapYear in a file called LeapYear.java. This class will hold the main method and the class method that we will write in this assignment. II. Write an empty public static void main(String[] args) method. This method should appear inside the curly braces of the LeapYear class. III. Write...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....