forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataTypesExample.java
43 lines (35 loc) · 1.22 KB
/
DataTypesExample.java
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
42
43
package InfinityJune21;
import java.util.Scanner; //1
public class DataTypesExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); //2
//Integer
//byte, short, int, long
byte b = scanner.nextByte();
short s = scanner.nextShort();
int i = scanner.nextInt();
long l = scanner.nextLong();
System.out.println("b: " + b + " s: " + s + " i: " + i + " l: " + l);
//"Java" + "Program" -> "JavaProgram"
//Decimal Value
//float, double
float f = scanner.nextFloat();
double d = scanner.nextDouble();
System.out.println("f: " + f + " d: " + d);
//Characters
//char
char c = scanner.next().charAt(0);
//Charcter: 'c', '3', '$'
//String: "Java", "Computer"
System.out.println("c: " + c);
//String
String s1 = scanner.next();
String s2 = scanner.nextLine();
System.out.println("s1: " + s1);
System.out.println("s2: " + s2);
//"Java" + 8 -> "Java8"
//Boolean
boolean b1 = scanner.nextBoolean();
System.out.println("b1: " + b1);
}
}