Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.lang.Integer.sum;
- import java.util.Scanner;
- public class Week2 {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- int sum = 0;
- int read;
- System.out.println("First number: ");
- read = Integer.parseInt(reader.nextLine());
- sum = read; //sum=read
- System.out.println("Second number: ");
- read = Integer.parseInt(reader.nextLine());
- sum += read; //sum(second)=sum(first)+read
- System.out.println("Third number: ");
- read = Integer.parseInt(reader.nextLine());
- sum += read; //sum(third)=(sum(first)+sum(second))+ read
- //sum(third)=sum
- System.out.println("Sum: " + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment