Advertisement
ItaiMaman

Sum of range of numbers

Dec 9th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. import java.util.*;
  2. public class ex3 {
  3. public static void main(String[] args) {
  4. Scanner in = new Scanner(System.in);
  5. int num1, num2, x, sum = 0;
  6. System.out.println("Enter two numbers");
  7. num1 = in.nextInt();
  8. num2 = in.nextInt();
  9. x = num1;
  10. while(x<=num2) {
  11. System.out.print(x + " ");
  12. sum+=x;
  13. x++;
  14. }
  15. System.out.println("Sum of numbers is " + sum);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement