In: Computer Science
Write an application that asks the user for a natural number. Display all the natural numbers up to and including the user's input. Also display the sum of all those numbers. JAVA
// Screenshot of the code & output
// Code to copy
SumNatural.java
import java.util.Scanner;
public class SumNatural {
public static void main(String[] args) {
int num , sum = 0;
Scanner input=new
Scanner(System.in);
System.out.print("Enter the natural
number: ");
num=input.nextInt();
for(int i = 1; i <= num; ++i)
{
System.out.print(i+" ");
sum += i;
}
System.out.println("\nSum = " + sum);
}
}