-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrahul.java
More file actions
102 lines (80 loc) · 2.14 KB
/
rahul.java
File metadata and controls
102 lines (80 loc) · 2.14 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
public class rahul {
public static void main(String[] args){
String firstName = "Rahul learning ";
String lastName = "Gupta ";
String fullName = firstName + lastName;
System.out.println(fullName);
byte myNum = 100;
System.out.println(myNum);
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
System.out.println(myInt); // Outputs 9
System.out.println(myDouble);
int x = 10;
x += 5;
System.out.println(x);
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt string is: " + txt.length());
System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD"
System.out.println(txt.toLowerCase());
String txts = "Please locate where 'locate' occurs!";
System.out.println(txts.indexOf("locate")); // Outputs 7
String firstNames = "John ";
String lastNames = "Doe";
System.out.println(firstNames.concat(lastNames));
String txtnew = "We are the so-called \"Vikings\" from the north.";
System.out.println(txtnew);
System.out.println(Math.max(5, 10));
int randomNum = (int)(Math.random() * 101); // 0 to 100
System.out.println(randomNum);
// comparison operator and if condition
int myAge = 2;
int votingAge = 18;
if (myAge >= votingAge) {
System.out.println("Old enough to vote!");
} else {
System.out.println("Not old enough to vote.");
}
int time = 22;
if (time < 10) {
System.out.println("Good morning.");
} else if (time < 18) {
System.out.println("Good day.");
} else {
System.out.println("Good evening.");
}
//
int tertime = 2;
String result = (tertime < 18) ? "Good day." : "Good evening.";
System.out.println(result);
// switch case
int day = 4;
day = 44;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Looking forward to the Weekend");
}
// Outputs "Thursday" (day 4)
}
}