Skip to content

Commit c86b1b8

Browse files
author
unknown
committed
Added CheckAge program
1 parent a1b7d24 commit c86b1b8

7 files changed

+85
-3
lines changed

.settings/org.eclipse.jdt.core.prefs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
44
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5-
org.eclipse.jdt.core.compiler.compliance=14
5+
org.eclipse.jdt.core.compiler.compliance=11
66
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
77
org.eclipse.jdt.core.compiler.debug.localVariable=generate
88
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -11,4 +11,4 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
1111
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
1212
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
1313
org.eclipse.jdt.core.compiler.release=enabled
14-
org.eclipse.jdt.core.compiler.source=14
14+
org.eclipse.jdt.core.compiler.source=11

src/AnotherClass.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
public class AnotherClass {
3+
public static void main(String[] args) {
4+
System.out.println("Hello World !!!");
5+
}
6+
}

src/CheckAge.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.Scanner;
2+
3+
public class CheckAge {
4+
5+
public static void main(String[] args) {
6+
int age = getAge();
7+
if (age < 0)
8+
System.out.println("Invalid age entered.");
9+
else if (age < 18)
10+
System.out.println("Person is a minor.");
11+
else
12+
System.out.println("Person is an adult.");
13+
}
14+
15+
private static int getAge() {
16+
Scanner scanner = new Scanner(System.in);
17+
18+
System.out.println("Input age to be checked: ");
19+
20+
if (scanner.hasNextInt()) {
21+
int age = scanner.nextInt();
22+
scanner.close();
23+
24+
if (age >= 0)
25+
return age;
26+
}
27+
28+
return -1;
29+
}
30+
31+
}

src/DisplaySquareAndCube.java

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static void main(String[] args) {
88

99
System.out.println("Square of 10 is: " + numSquared);
1010
System.out.println("Cube of 10 is: " + numCubed);
11+
1112

1213
}
1314

src/FirstPrg.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
public class FirstPrg {
3+
public static void main(String[] args) {
4+
int no = 100; // initialize variable
5+
int num; // Declare variable
6+
num = 200; // Assigning value to variable
7+
8+
int add = no + num;
9+
System.out.println("Addition : " + add);
10+
}
11+
}

src/Loop.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
public class Loop {
3+
public static void main(String[] args) {
4+
int no = 1;
5+
int lastNo = 10;
6+
7+
while(no <= lastNo) {
8+
System.out.print(no + ", ");
9+
no ++;
10+
}
11+
12+
no = 100;
13+
do {
14+
System.out.println("\n\nIside do_while");
15+
System.out.println("no = " + no);
16+
} while(no <= lastNo);
17+
18+
for(no = 1; no<=10; no++) {
19+
System.out.print(no + ", ");
20+
}
21+
}
22+
}

src/WorkingWithSop.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
public class WorkingWithSop {
3+
public static void main(String[] args) {
4+
int no = 10;
5+
int nextNum = 20;
6+
7+
System.out.println("no + nextNum = " + (no + nextNum));
8+
System.out.println(no + " + " + nextNum + " = " + no + nextNum);
9+
System.out.println(no + nextNum + " = " + no + nextNum);
10+
}
11+
}

0 commit comments

Comments
 (0)