-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionals.java
More file actions
54 lines (48 loc) · 1.76 KB
/
Copy pathConditionals.java
File metadata and controls
54 lines (48 loc) · 1.76 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
package Week3;
public class Conditionals {
public static void main(String[] args) {
//conditionals
int age = 19;
double gpa = 3.2;
char letterGrade = 'A';
boolean csMajor = true;
boolean isStudent = false;
boolean isTeacher = true;
boolean isTeacherCsMajor = true;
String name = "Krista";
String favoriteColor = "Blue";
if(age<21){
System.out.println("You are younger than 21");
}else{
System.out.println("You are older than 21");
}
if(gpa>=4.0){
System.out.println("You get an A");
}else if (gpa>=3.6){
System.out.println("You get a A-");
} else if (gpa>=2.7) {
System.out.println("You get a B");
} else if (gpa>=1.7) {
System.out.println("You get a C");
}else{
System.out.println("you get less than a C");}
//relational operator
//< > <= >= == !=
if (csMajor == isStudent){
System.out.println("This person is a student and a cs major");
}else{
if (isTeacher != isStudent){
System.out.println("This person is a teacher and may be a student");
}else if(isTeacher == isTeacherCsMajor){
System.out.println("This person is a teacher and a cs major");
}
System.out.println("The person is either not a student not a cs major or neither");
}
String name2 = "bob";
if (!name.equals(name2)){
System.out.printf("The name %s is not equal to the name %s", name, name2);
}else{
System.out.println("The names are equal");
}
}
}