0
Using a while loop write a java program that will prompt a user to enter two integers using a keyboard and return their sum.
Using a while loop write a java program that will prompt a user to enter two integers using a keyboard and return their sum.To exit the loop the user must enter zero.
2 ответов
+ 2
import java.util.Scanner;
class Sample{
public static void main(String args[]){
int a,b;
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("Enter first number");
a = sc.nextInt();
System.out.println("Enter another number");
b = sc.nextInt();
System.out.println("Addition =" +a+b);
System.out.println("Enter 0 if you want to close");
close = sc.nextInt();
if(close == 0)
break;
}
}
}
+ 1
Is this homework or something?