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.
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.
Get Answers For Free
Most questions answered within 1 hours.