Answer:
import java.util.Scanner;
public class NumberSum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num, sum=0,num1=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter a number");
num=input.nextInt();
input.close();
do{
System.out.println(num1);
num1+=1;
sum+=num1;
}while(num1<=num);
System.out.println(sum);
}
}