476179

whileChallenge

Nov 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. package act;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Challenge
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. Scanner k = new Scanner(System.in);
  11.  
  12. System.out.print("enter a nonzero positive number: ");
  13. int max = k.nextInt();
  14. int it = 0;
  15. int sum = 0;
  16. do {
  17. it ++;
  18. sum = sum + it;
  19.  
  20. }while (it < max);
  21. System.out.println("the sum of the numbers between 1 and "+max+" is "+sum);
  22. k.close();
  23. }
  24.  
  25. }
Add Comment
Please, Sign In to add comment