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.

13th Oct 2017, 9:46 AM
Hammy
Hammy - avatar
2 Answers
+ 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; } } }
13th Oct 2017, 11:19 AM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 1
Is this homework or something?
13th Oct 2017, 6:11 PM
Rrestoring faith
Rrestoring faith - avatar