You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+152-3
Original file line number
Diff line number
Diff line change
@@ -134,6 +134,7 @@ Also, to make this class more usable, you may want to add methods to insert and
134
134
135
135
---
136
136
137
+
137
138
### Compute_CircleArea.java
138
139
**Code:**
139
140
```Java
@@ -171,6 +172,7 @@ public class Main {
171
172
doubleArea;
172
173
double pi;
173
174
175
+
174
176
pi =3.14159;
175
177
176
178
System.out.println("Enter radius: ");
@@ -186,6 +188,7 @@ public class Main {
186
188
This Java program calculates the area of a circle based on user input. The program uses the Scanner class to take input from the user. The variable "r" is used to store the radius of the circle entered by the user, "pi" is used to store the value of pi (3.14159 in this case), and "Area" is used to store the calculated area of the circle (r*r * pi). The program first prompts the user to "Enter radius: " and then assigns the value entered by the user to the variable "r" using the nextDouble() method of the Scanner class. Then it calculates the area of the circle and prints the message "Area of a Circle is" followed by the calculated area of the circle using the "System.out.println" method.
187
189
188
190
---
191
+
189
192
### Compute_mean_input.java
190
193
**Code:**
191
194
@@ -202,7 +205,7 @@ public class Main {
202
205
int mean = (num1+num2+num3)/3;
203
206
System.out.println("The mean value is: "+mean);
204
207
205
-
208
+
206
209
}
207
210
208
211
}
@@ -221,7 +224,6 @@ This Java program calculates the mean of three integers entered by the user. The
221
224
importjava.applet.Applet;
222
225
importjava.awt.Graphics;
223
226
224
-
225
227
publicclassDuckyextendsJApplet
226
228
{
227
229
// Overriding paint() method
@@ -230,12 +232,14 @@ public class Ducky extends JApplet
230
232
{
231
233
g.drawString("Hello World", 20, 20);
232
234
}
233
-
235
+
234
236
}
235
237
236
238
```
237
239
This is a Java applet program that displays the message "Hello World" on the screen. The program is a subclass of the Applet class, which is a built-in Java class for creating applets. The program overrides the paint() method of the Applet class, which is called automatically when the applet is run. Inside the paint() method, the program uses the drawString() method of the Graphics class to display the message "Hello World" at the coordinates (20, 20) on the screen. The program extends JApplet class, JApplet is a class from javax.swing package that you can use to create an Applet, but it is not the only way to create an Applet.
238
240
241
+
---
242
+
239
243
### classes.java
240
244
**Code:**
241
245
```java
@@ -325,4 +329,149 @@ Then the program uses the "System.out.println" method to output the value of the
325
329
Since the variable x is an instance variable, it has a different value for each object, but in this case, the value of the variable is the same for both instances of the Main class and it is not modified inside the main method, so the two System.out.println lines will print the same value, which is 100.
326
330
327
331
---
332
+
### condtions.java
333
+
**Code:**
334
+
335
+
```java
336
+
publicclassMain {
337
+
publicstaticvoidmain(String[] args) {
338
+
339
+
if (21<=20)
340
+
{
341
+
System.out.println(true);
342
+
} elseif (21>=21){
343
+
System.out.println(false);
344
+
}
345
+
346
+
}
347
+
348
+
}
349
+
350
+
```
351
+
This code defines a class "Main" that contains a "main" method. Inside the main method, an "if-else" statement is used to check if 21 is less than or equal to 20. If this evaluates to true, the program prints "true" to the console. If not, it then checks if 21 is greater than or equal to 21, if so it will print "false" to the console.
352
+
353
+
The if condition will never be true, so the program will only output "false"
354
+
355
+
---
356
+
357
+
### for.java
358
+
**Code:**
359
+
360
+
```java
361
+
publicclassMain{
362
+
publicstaticvoidmain(String[] args) {
363
+
for (int i =0; i <10; i++)
364
+
System.out.println(i);
365
+
366
+
String[] fruits = {"Apple","Banana", "Orange"};
367
+
for (String i : fruits)
368
+
System.out.println(fruits);
369
+
370
+
}
371
+
}
372
+
```
373
+
This code defines a class "Main" that contains a "main" method. Inside the main method, there are two for loops. The first for loop uses the variable "i" and iterates from 0 to 9, printing the value of "i" to the console on each iteration.
374
+
375
+
The second for loop is an enhanced for loop, also known as a "for-each" loop, which is used to iterate over an array or collection. It uses the variable "i" to iterate through the "fruits" array, and on each iteration, it prints the value of "i" to the console.
376
+
377
+
However, the second for loop, the print statement is using System.out.println(fruits); instead of System.out.println(i); which will print the whole array ["Apple","Banana", "Orange"] in each iteration instead of the current element.
378
+
379
+
---
380
+
381
+
### forbreak.java
382
+
**Code:**
383
+
```java
384
+
publicclassMain{
385
+
publicstaticvoidmain(String[] args){
386
+
387
+
int i =0;
388
+
while (i <10) {
389
+
if (i ==4) {
390
+
i++;
391
+
continue;
392
+
}
393
+
System.out.println(i);
394
+
i++;
395
+
}
396
+
}
397
+
398
+
}
399
+
```
400
+
This code defines a class "Main" that contains a "main" method. Inside the main method, there is a "while" loop. The loop uses the variable "i" as the loop counter and it starts with the value of 0. The loop continues to execute as long as the value of "i" is less than 10.
401
+
402
+
Inside the loop, there is an "if" statement that checks if the value of "i" is equal to 4. If this evaluates to true, the program increases the value of "i" by 1 and then uses the "continue" statement to skip the rest of the current iteration of the loop, and move to the next iteration.
328
403
404
+
If the value of "i" is not equal to 4, the program will print the value of "i" to the console and then increase the value of "i" by 1.
405
+
406
+
In summary, this program will print the numbers from 0 to 9 to the console, except for the number 4, which will be skipped.
407
+
408
+
---
409
+
410
+
### forloop.java
411
+
**Code:**
412
+
413
+
```java
414
+
publicclassMain{
415
+
publicstaticvoidmain(String[] args) {
416
+
417
+
String[] fruits = {"Apple","Banana", "Orange"};
418
+
for (String i : fruits)
419
+
System.out.println(fruits);
420
+
421
+
}
422
+
}
423
+
424
+
```
425
+
This code defines a class "Main" that contains a "main" method. Inside the main method, there's an enhanced for loop, also known as a "for-each" loop, which is used to iterate over an array or collection.
426
+
It uses the variable "i" to iterate through the "fruits" array, and on each iteration, it prints the whole array ["Apple","Banana", "Orange"] using the statement System.out.println(fruits);. The current element 'i' is not being used inside the print statement.
427
+
428
+
It will print the same array 3 times on the console, instead of the current element of the array which is the expected output, to print the current element you should use System.out.println(i);
429
+
430
+
---
431
+
432
+
### forloop_2.java
433
+
**Code:**
434
+
```java
435
+
publicclassMain {
436
+
publicstaticvoidmain(String[] args){
437
+
for (int k =0; k <5; k++ )
438
+
System.out.println("numbers"+k);
439
+
440
+
}
441
+
}
442
+
443
+
```
444
+
This code defines a class "Main" that contains a "main" method. Inside the main method, there is a for loop that uses the variable "k" as a loop counter. The loop starts with the value of "k" as 0 and continues to execute as long as "k" is less than 5.
445
+
On each iteration, it prints the string "numbers" concatenated with the current value of k using the statement System.out.println("numbers" +k);. So the output will be "numbers0", "numbers1", "numbers2", "numbers3" and "numbers4"
446
+
447
+
This program will print the numbers from 0 to 4 on the console with the string "numbers" before each number.
448
+
449
+
---
450
+
451
+
### forloop_MathAdd.java
452
+
**Code:**
453
+
```java
454
+
publicclassMain {
455
+
publicstaticvoidmain(String[] args){
456
+
457
+
int add =0;
458
+
for (int k =0; k <5; k++ ){
459
+
460
+
add = add + k;
461
+
462
+
}
463
+
464
+
System.out.println("numbers: "+add);
465
+
}
466
+
}
467
+
468
+
```
469
+
This code defines a class "Main" that contains a "main" method. Inside the main method, there is a for loop that uses the variable "k" as a loop counter. The loop starts with the value of "k" as 0 and continues to execute as long as "k" is less than 5.
470
+
471
+
There's an integer variable add initialized with 0, and on each iteration of the loop, the current value of "k" is added to the add variable using the statement add = add + k;
472
+
473
+
After the for loop, the program prints the final value of the add variable concatenated with the string "numbers: " using the statement System.out.println("numbers: " +add);.
474
+
475
+
This program will print the sum of numbers from 0 to 4 on the console with the string "numbers: " before the sum. The sum would be 10.
0 commit comments