-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh04_21_Practice8.java
More file actions
60 lines (48 loc) · 1.84 KB
/
Ch04_21_Practice8.java
File metadata and controls
60 lines (48 loc) · 1.84 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
import java.util.Scanner;
public class Ch04_21_Practice8 {
public static void main(String[] args) {
//Operator Precedence Question
int A = 10 + 5 * 2 - 15 / 3;
// Expected Answer - 10 + 10 - 5 -> 15
System.out.println("Answer of Precedence and Associativity Answer: " + A);
System.out.println(" ");
//Increment Decrement -
int x = 5; // x = 5
int y = ++x; // y = 1+x = 1+5 = 6 , x = 6
int z = y--; // z = 6(-1) , y = 5 , Ultimately , x = 6 , y = 5 and z = 6
System.out.printf("x: %d , y: %d , z: %d" , x,y,z);
System.out.println(" ");
// String Manipulation
String str = "Programming in Java";
System.out.println("Length of string: " + str.length());
System.out.println("Extracting Java: " + str.substring(str.length()-4));
System.out.println("String in uppercase: " + str.toUpperCase());
System.out.println(" ");
// Operator Result
boolean x1 = 7%3 == 1 && 10/2 > 4; // true && true = true
System.out.println("Boolean answer: " + x1);
System.out.println(" ");
//Vote eligibility
System.out.print("Enter your age: ");
Scanner input = new Scanner(System.in);
float age = input.nextInt();
if (age>= 18){
System.out.println("Eligible to Vote");
}
else {
System.out.println("Not eligible to vote");
}
System.out.println(" ");
//Logical operators
boolean isRaining = true;
boolean hasUmbrella = false;
boolean isNotRaining = !isRaining;
if ((isRaining && hasUmbrella) || isNotRaining){
System.out.println("Let's go outside");
}
else{
System.out.println("Not Today!");
}
System.out.println("******");
}
}