-
Notifications
You must be signed in to change notification settings - Fork 1
/
NLecture01.java
203 lines (171 loc) · 4.62 KB
/
NLecture01.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import java.util.Scanner;
public class NLecture01 {
//control structure
public static void main(String[] args)
{
/* int marks = 30;
if(marks>=50)
{
System.out.println("Pass");
} */
Scanner input = new Scanner(System.in);
/* System.out.print("Enter your marks: ");
int marks= input.nextInt();
if(marks>=70)
System.out.println("A\nExcellent");
else if(marks>=60)
System.out.println("B+\nVery Good");
else if(marks>=50)
System.out.println("B\nGood");
else if(marks>=40)
System.out.println("C\nPass");
else if(marks>=35)
System.out.println("D\nPoor");
else
System.out.println("F\nFail\nLazy\nYou are not part of us"); */
//switch
/* System.out.println("Please enter your number to print out a day");
int day=input.nextInt();
switch(day){
case 1:
System.out.println("Monday");
System.out.println("Start of the week");
System.out.println("ZNZ");
break;
case 2:
System.out.println("Tue");
break;
case 3:
System.out.println("Wed");
break;
case 4:
System.out.println("Thu");
break;
case 5:
System.out.println("Friday");
break;
default:
System.out.println("Weekend");
System.out.println("Kendwa Rocks");
break;
} */
//Repetition
/* for(int i=1;i<=100;i++)
{
if(i%2==0)
System.out.println(i);
} */
//while loop
//infinite loop
/* boolean flag = true;
while(flag)
{
System.out.println("Welcome to SOB Ndondo Cup");
} */
//finite loop
/*
pre test loop
int i=1;
while(i<=10){
System.out.println(i);
i++;
} */
//post test loop
/* int i=0;
do{
System.out.println(i);
i++;
}while(i<=10); */
//break and continue
/* for(int i=1;i<=10;i++)
{
if(i==5)
break;
if(i==5)
continue;
else
System.out.println(i);
} */
//nested if and nested loop
/* int a,b,c;
a=input.nextInt();
b=input.nextInt();
c=input.nextInt();
if(a>b)
{
if(a>c)
System.out.println(a+" is maximum number");
else
System.out.println(c+" is maximum number");
}
else
{
if(b>c)
System.out.println(b+" is maximum number");
else
System.out.println(c+" is maximum number");
}
*/
//nested loop
/* for(int h=0;h<=23;h++)
{
for(int m=0;m<=59;m++)
{
for(int s=0;s<=59;s++)
{
System.out.println(h+":"+m+":"+s);
}
}
} */
//calling function
/* displayMessage();
System.out.println("Summation of two Numbers is: "+calculateSum(4, 6)); */
/* System.out.println(first_if_funct(-1,5)); */
//array
/* int[] age = {3,4,6,8,10};
System.out.println(age[0]);//3
System.out.println(age[3]);//8
System.out.println(age[4]);//10
System.out.println(age[5]);//error */
int[] a=new int[10];
for(int i=0;i<=9;i++)
{
a[i]=input.nextInt();
}
int sum=0;
for(int j=0;j<=9;j++)
{
System.out.println(a[j]);
sum+=a[j];
}
System.out.println("Sum is:"+sum);
System.out.println("Average "+sum/10);
}
//functions
/* static void displayMessage()
{
System.out.println("Welcome to SoB");
}
static int calculateSum(int n1,int n2)
{
return n1+n2;
}
static double firstFunction(int x,int y)
{
return ((y*y)/x+Math.sqrt(x)*y);
}
static double secondFunction(int x,int y)
{
return Math.pow((x+2),3)+y;
}
static double first_if_funct(int x,int y)
{
if(x>0)
return firstFunction(x, y);
else if(x<0)
return secondFunction(x, y);
else
return x;
}
*/
}