-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson_9.java
More file actions
82 lines (66 loc) · 1.67 KB
/
Copy pathlesson_9.java
File metadata and controls
82 lines (66 loc) · 1.67 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
/*_______________________________*/
//! Do While Loop!!
package Notes;
import java.util.Scanner;
public class lesson_9 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
//!Average Grade
int counter =1;
int grade = 0, sum=0;
do{
System.out.print("Enter grade for student no "+counter +" : ");
grade = input.nextInt();
sum +=grade;
counter++;
}while(counter<=6);
System.out.println("Average Grade is "+sum/counter);
//! Menu & Select Action
int option;
int num1=20, num2=10;
do{
System.out.println("Select an option from the MENU");
System.out.println("1. Sum 2 numbers");
System.out.println("2. Subtract 2 numbers");
System.out.println("3. Divide 2 numbers");
System.out.println("0. Exit");
option = input.nextInt();
switch(option){
case 1:
System.out.println("Sum of the 2 numbers is "+(num1+num2));
break;
case 2:
System.out.println("Subtract of the 2 numbers is "+(num1-num2));
break;
case 3:
System.out.println("Divide of the 2 numbers is "+(num1/num2));
break;
case 0:
System.out.println("Good Bye!!");
break;
default:
System.out.println("Invalid Option");
}
} while(option !=0);
input.close();
}
}
/*_______________________________*/
//! Do While Loop:
/*
do{
this;
and this;
...
} while(this condition is true)
*/
/*_______________________________*/
//! While Loop
/*
while(this condition is true){
this;
and this;
...
}
*/
/*_______________________________*/