-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIntegerDemoInteractiveWithName.java
More file actions
41 lines (30 loc) · 1.1 KB
/
Copy pathIntegerDemoInteractiveWithName.java
File metadata and controls
41 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class IntegerDemoInteractiveWithName
{
public static void main(String[] args)
{
String name;
int anInt; // One must keep the data types
byte aByte; // They are not inhereted when the
short aShort; // Input takes place
long aLong;
Scanner input = new Scanner(System.in);
System.out.print("Please enter an integer >> ");
anInt = input.nextInt();
System.out.print("Please enter a byte integer >> ");
aByte = input.nextByte();
System.out.print("Please enter a short integer >> ");
aShort = input.nextShort();
System.out.print("Please enter Long integer >> ");
aLong = input.nextLong();
input.nextLine(); // Line added to consume the Enter
// from the buffer storage!!! ** ** ***
System.out.print("Please enter your name >> ");
name = input.nextLine();
System.out.println("Thank you. " + name);
System.out.println("The int is " + anInt);
System.out.println("The byte is " + aByte);
System.out.println("The short is a " + aShort);
System.out.println("The long is " + aLong);
}
}