Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Sum of 2 numbers with Repeatly in Java

  1. //sum of 2 numbers with repeated loop
  2. import java.io.*;
  3. class Addition1
  4. {
  5. public static void main(String args[])throws IOException
  6. {
  7. int a,b,c;
  8. String ch;
  9.  
  10. BufferedReader br= new BufferedReader( new InputStreamReader(System.in));
  11. do
  12. {
  13. System.out.println("Enter the two numbers to add:");
  14. a=Integer.parseInt(br.readLine());
  15. b=Integer.parseInt(br.readLine());
  16. c = a+b;
  17. System.out.println("Sum of two numbers:"+ c);
  18. System.out.println("Do u want to continue(y/n)?");
  19. ch=br.readLine();
  20. }while( ch.equals( "yes") || ch.equals( "YES") );
  21. }
  22. }


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