Skip to content

Commit 36816e1

Browse files
committed
init
1 parent 4a631dc commit 36816e1

39 files changed

+1307
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>demo</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>22</maven.compiler.source>
13+
<maven.compiler.target>22</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public class CastingDemo {
2+
3+
public static void main(String[] args) {
4+
5+
// convert double to int
6+
double theDoubleGradeAvg = 89.70;
7+
int theIntGradeAvg = (int) theDoubleGradeAvg;
8+
9+
System.out.println("theDoubleGradeAvg=" + theDoubleGradeAvg);
10+
System.out.println("theIntGradeAvg=" + theIntGradeAvg);
11+
12+
// convert float to byte
13+
float theFloatDistance = 123.60f;
14+
byte theByteDistance = (byte) theFloatDistance;
15+
16+
System.out.println("theFloatDistance=" + theFloatDistance);
17+
System.out.println("theByteDistance=" + theByteDistance);
18+
19+
// convert int to char
20+
int theCharacterCode = 65;
21+
char theChar = (char) theCharacterCode;
22+
23+
System.out.println("theCharacterCode=" + theCharacterCode);
24+
System.out.println("theChar=" + theChar);
25+
26+
// convert String to int
27+
int count = Integer.parseInt("49");
28+
System.out.println("count=" + count);
29+
}
30+
}
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Demo {
2+
3+
public static void main(String[] args) {
4+
5+
// add our code here
6+
System.out.println("Hello World of Java!");
7+
System.out.println("My favorite color is blue.");
8+
System.out.println("My hobby is coding.");
9+
10+
}
11+
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class NumberDemo {
2+
3+
public static void main(String[] args) {
4+
5+
double gradeExam1 = 87.5;
6+
double gradeExam2 = 100.0;
7+
double gradeExam3 = 66.50;
8+
9+
double gradeAverage = (gradeExam1 + gradeExam2 + gradeExam3) / 3;
10+
11+
System.out.println("Grade exam 1: " + gradeExam1);
12+
System.out.println("Grade exam 2: " + gradeExam2);
13+
System.out.println("Grade exam 3: " + gradeExam3);
14+
System.out.println("Grade average: " + gradeAverage);
15+
16+
// format the output
17+
String formattedAvg = String.format("%.2f", gradeAverage);
18+
System.out.println("Formatted average: " + formattedAvg);
19+
20+
}
21+
}
22+
23+
24+
25+
26+
27+
28+
29+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Scanner;
2+
3+
public class NumberInputDemo {
4+
5+
public static void main(String[] args) {
6+
7+
Scanner scanner = new Scanner(System.in);
8+
9+
System.out.print("Enter grade exam 1: ");
10+
double gradeExam1 = scanner.nextDouble();
11+
12+
System.out.print("Enter grade exam 2: ");
13+
double gradeExam2 = scanner.nextDouble();
14+
15+
System.out.print("Enter grade exam 3: ");
16+
double gradeExam3 = scanner.nextDouble();
17+
18+
double gradeAverage = (gradeExam1 + gradeExam2 + gradeExam3) / 3;
19+
20+
System.out.println("Grade exam 1: " + gradeExam1);
21+
System.out.println("Grade exam 2: " + gradeExam2);
22+
System.out.println("Grade exam 3: " + gradeExam3);
23+
System.out.println("Grade average: " + gradeAverage);
24+
25+
// format the output
26+
String formattedAvg = String.format("%.2f", gradeAverage);
27+
System.out.println("Formatted average: " + formattedAvg);
28+
29+
scanner.close();
30+
}
31+
}
32+
33+
34+
35+
36+
37+
38+
39+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
public class StringDemo {
2+
3+
public static void main(String[] args) {
4+
5+
/*
6+
var message = "Hello World!";
7+
var extra = "I love to code!";
8+
*/
9+
10+
String message = "Hello World!";
11+
String extra = "I love to code!";
12+
13+
System.out.println(message + " " + extra);
14+
15+
System.out.println("Length of " + message + " is " + message.length());
16+
System.out.println("Upper case version of " + message + " is " + message.toUpperCase());
17+
System.out.println("Lower case version of " + message + " is " + message.toLowerCase());
18+
19+
String combo = message + " " + extra;
20+
System.out.println("Combo: " + combo);
21+
22+
String upperVersion = combo.toUpperCase();
23+
System.out.println("Upper version: " + upperVersion);
24+
25+
}
26+
}
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Scanner;
2+
3+
public class StringInputDemo {
4+
5+
public static void main(String[] args) {
6+
7+
// Create a scanner for reading input from the user
8+
Scanner scanner = new Scanner(System.in);
9+
10+
// prompt the user
11+
System.out.print("What is your favorite color? ");
12+
13+
// read the input from the user
14+
String theColor = scanner.nextLine();
15+
16+
// prompt the user
17+
System.out.print("What is your hobby? ");
18+
19+
// read the input from the user
20+
String theHobby = scanner.nextLine();
21+
22+
System.out.println("Your favorite color is " + theColor);
23+
System.out.println("Your hobby is " + theHobby);
24+
25+
// close to release resources and prevent resource/memory leaks
26+
scanner.close();
27+
}
28+
}
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>helloworld</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>22</maven.compiler.source>
13+
<maven.compiler.target>22</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
</project>

0 commit comments

Comments
 (0)