SumOfInput.java 525B

12345678910111213141516171819202122232425
  1. /**
  2. * Created by iyasuwatts on 10/17/17.
  3. */
  4. import java.util.Scanner;
  5. public class SumOfInput {
  6. public static void main(String[] args){
  7. Scanner scan = new Scanner(System.in);
  8. System.out.println("Input a number:");
  9. int number = scan.nextInt();
  10. int total = 0;
  11. System.out.println("Your number is " + number + "!");
  12. for(int i = 1; i <= number; i++){
  13. total += i;
  14. }
  15. System.out.println("The sum is: " + total);
  16. }
  17. }