Skip to content

Commit a7fb8d6

Browse files
committed
First day
1 parent c7735e9 commit a7fb8d6

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

AreaOfRectangle.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Scanner;
2+
3+
public class AreaOfRectangle {
4+
public static void main(String[] args) {
5+
6+
// Calculate area of rectangle
7+
8+
double width = 0;
9+
double height = 0;
10+
double area = 0;
11+
12+
Scanner scanner = new Scanner(System.in);
13+
14+
System.out.print("Enter the width: ");
15+
width = scanner.nextDouble();
16+
17+
System.out.print("Enter the height: ");
18+
height = scanner.nextDouble();
19+
20+
area = width * height;
21+
22+
System.out.println("The area is: " + area + "cm");
23+
24+
scanner.close();
25+
}
26+
}

Madlibs.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.Scanner;
2+
3+
public class Madlibs {
4+
public static void main(String[] args) {
5+
6+
// Madlibs game
7+
8+
Scanner scanner = new Scanner(System.in);
9+
10+
String adjective1;
11+
String noun1;
12+
String adjective2;
13+
String verb1;
14+
String adjective3;
15+
16+
System.out.print("Enter an adjective (description): ");
17+
adjective1 = scanner.nextLine();
18+
19+
System.out.print("Enter a noun (animal or person): ");
20+
noun1 = scanner.nextLine();
21+
22+
System.out.print("Enter an adjective (description): ");
23+
adjective2 = scanner.nextLine();
24+
25+
System.out.print("Enter a verb (action): ");
26+
verb1 = scanner.nextLine();
27+
28+
System.out.print("Enter an adjective (description): ");
29+
adjective3 = scanner.nextLine();
30+
31+
System.out.println("\nToday I went to a " + adjective1 + " zoo.");
32+
System.out.println("In an exhibit, I saw a " + noun1 + ".");
33+
System.out.println(noun1 + " was " + adjective2 + " and " + verb1 + "!");
34+
System.out.println("I was " + adjective3 + "!");
35+
36+
scanner.close();
37+
}
38+
}

UserInput.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.Scanner;
2+
3+
public class UserInput {
4+
public static void main(String[] args) {
5+
6+
// User input and input buffer
7+
8+
Scanner scanner = new Scanner(System.in);
9+
10+
System.out.print("Enter your name: ");
11+
String name = scanner.nextLine();
12+
13+
System.out.print("Enter your age: ");
14+
int age = scanner.nextInt();
15+
scanner.nextLine(); // To catch input buffer, we use scanner.nextLine()
16+
17+
System.out.print("Enter your gpa: ");
18+
double gpa = scanner.nextDouble();
19+
scanner.nextLine(); // To catch input buffer, we use scanner.nextLine()
20+
21+
System.out.print("Are you a student? (true/false): ");
22+
boolean isStudent = scanner.nextBoolean();
23+
24+
System.out.println("Your name is " + name);
25+
System.out.println("You are " + age + " years old");
26+
System.out.println("Your gpa is : " + gpa);
27+
28+
if(isStudent) {
29+
System.out.println("You are a student.");
30+
} else {
31+
System.out.println("You are NOT a student.");
32+
}
33+
34+
scanner.close();
35+
}
36+
}

0 commit comments

Comments
 (0)