Advertisement
PadmaJS

Exercise 4.25

Sep 28th, 2022
3,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise4_25 {
  4.   public static void main(String[] args) {
  5.     Scanner in = new Scanner(System.in);
  6.     System.out.print("Enter a number: ");
  7.     int number = in.nextInt();
  8.     int sum = 0;
  9.     for (int i = 1; i <= number; i++) {
  10.       for (var j = 1; j <= i; j++) {
  11.         sum += j;
  12.       }
  13.     }
  14.     System.out.println("The sum upto " + number + " is " + sum);
  15.   }
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement