Advertisement
Guest User

The sum between two numbers

a guest
Feb 7th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class TheSumBetweenTwoNumbers {
  5.     public static void main(String[] args) {
  6.         Scanner reader = new Scanner(System.in);
  7.        
  8.         System.out.println("First:");
  9.         int first = Integer.parseInt(reader.nextLine());
  10.        
  11.         System.out.println("Last:");
  12.         int last = Integer.parseInt(reader.nextLine());
  13.        
  14.         int y = 0;
  15.         int sum = 0;
  16.        
  17.            while (y >= last) {
  18.            sum = sum + y;
  19.            y++;
  20.            
  21.            
  22.            }
  23.            
  24.            System.out.println("The sum is " + sum);
  25.     }
  26.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement