-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 1
More file actions
104 lines (83 loc) · 2.75 KB
/
Copy pathAssignment 1
File metadata and controls
104 lines (83 loc) · 2.75 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
103
104
import java.util.Scanner;
public class Assignment1 {
public static void main(String[] args) {
// Question 1 : Write a Java program to get a number from the user and print whether it is positive or negative.
Scanner sc = new Scanner(System.in);
System.out.println("Enter your number");
int num = sc.nextInt();
if (num > 0){
System.out.println("Number is Positive");
}
else if(num == 0){
System.out.println("Number is Zero");
}
else{
System.out.println("Number is Negative");
}
// Question 2 : Finish the following code so that it prints You have a fever if your temperature is above 100 and otherwise prints You don't have a fever.
// public class Solution {
// public static void main(String[] args) {
// double temp = 103.5;
// }
double temp = 103.5;
if(temp > 100){
System.out.println("You have Fever");
}
else{
System.out.println("You don't have Fever");
}
// Question 3 : Write a Java program to input week number(1-7) and print day of week name using switch case.
System.out.println("Enter your week number from 1 to 7");
int weak_num = sc.nextInt();
switch(weak_num){
case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
break;
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday");
break;
case 5:
System.out.println("Thursday");
break;
case 6:
System.out.println("Friday");
break;
case 7:
System.out.println("Saturday");
break;
default:
System.out.println("You entered a wrong Week Number");
}
// Question 4 : What will be the value of x & y in the following program:
// public class Solution {
// public static void main(String args[]) {
// int a = 63, b = 36;
// boolean x = (a < b ) ? true : false;
// int y= (a > b ) ? a : b;
// }
// }
int a = 63, b = 36;
boolean x = (a < b ) ? true : false;
int y = (a > b ) ? a : b;
System.out.println(x);
System.out.println(y);
// Question 5 : Write a Java program that takes a year from the user and print whether that year is a leap year or not.
System.out.println("Enter Year");
int year = sc.nextInt();
boolean x = (year % 4) == 0;
boolean y = (year % 100) !=0;
boolean z = (year % 100 == 0) && (year % 400 == 0);
if(x && (y || z)){
System.out.println(year + " is a leap year");
}
else{
System.out.println(year + " is not a leap year");
}
}
}