SOLUTION:
import java.util.Scanner;
public class Num{
public static void main(String[] args){
int sum=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number:");
int n=sc.nextInt();
for(int i=1;i<=n;i++){
sum=sum+n;
}
System.out.println("The sum from 1 to"+n+"is:"+sum);
}
}
Example:
input:5
output: The sum from 1 to 5 is:15