HarrJ

Day 16 b

Aug 17th, 2023
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Day16B {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. String txtIn;
  7. int numStart=0,numEnd = 0,numSum = 0;
  8. //initialize the variables
  9.  
  10. try {
  11. System.out.print("Enter number 1:");
  12. txtIn = sc.nextLine();
  13. numStart = Integer.parseInt(txtIn);
  14. System.out.print("Enter number 2:");
  15. txtIn = sc.nextLine();
  16. numEnd = Integer.parseInt(txtIn);
  17. } catch (Exception e) {
  18. System.out.println("One of the numbers is invalid");
  19. }
  20. System.out.println();
  21. if (numStart < numEnd) {
  22. for (int i = numStart; i <= numEnd; i++) {
  23. System.out.printf("%d + ", i);
  24. numSum += i;
  25. }
  26. } else {
  27. // gawa kayo ng for loop same as above ang code pero from
  28. // numEnd to numStart bale countdown
  29. }
  30.  
  31. System.out.printf("0 = %d", numSum);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment