Repository navigation
Expand file tree
/
Copy pathassignment3.java
More file actions
89 lines (83 loc) · 2.55 KB
/
Copy pathassignment3.java
File metadata and controls
89 lines (83 loc) · 2.55 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
// ASSIGNMENT 3
import java.util.*;
// Question 1 : Write a Java program to get a number from the user and print whether it is positive or negative.
class PosNeg {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if (a >= 0) {
System.out.println("positive");
} else {
System.out.println("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.
class Fever {
public static void main(String[] args) {
double temp = 103.5;
if (temp > 100) {
System.out.println("Fever");
} else {
System.out.println("No Fever");
}
}
}
// Question 3 : Write a Java program to input week number (1-7) and print day of
// week name using switch case.
class Week {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int day = sc.nextInt();
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:
break;
}
}
}
// Question 4 :What will be the value of x & y in the following program
// ans = x : false , y : 63
// Question 5 : Write a Java program that takes a year from the user and print
// whether that year is a leap year or not.
class LeapYear {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
System.out.println("Leap year");
} else {
System.out.println("Not a leap year");
}
} else {
System.out.println("Leap Year");
}
} else {
System.out.println("Not a leap year");
}
}
}