//sum of 2 numbers with repeated loop import java.io.*; class Addition1 { public static void main(String args[])throws IOException { int a,b,c; String ch; BufferedReader br= new BufferedReader( new InputStreamReader(System.in)); do { System.out.println("Enter the two numbers to add:"); a=Integer.parseInt(br.readLine()); b=Integer.parseInt(br.readLine()); c = a+b; System.out.println("Sum of two numbers:"+ c); System.out.println("Do u want to continue(y/n)?"); ch=br.readLine(); }while( ch.equals( "yes") || ch.equals( "YES") ); } }
Output: |
---|
Enter the two numbers to add: |
2 |
3 |
Sum of two numbers:5 |
Do u want to continue(y/n)? |
yes |
Enter the two numbers to add: |
3 |
4 |
Sum of two numbers:7 |
Do u want to continue(y/n)? |
no |