-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava_input
72 lines (53 loc) · 2.48 KB
/
Java_input
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
import java.util.Scanner;
public class Java_input {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// example_1 -> sum two numbers
System.out.print("Enter first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter second number: ");
int num2 = scanner.nextInt();
int sum = num1 + num2;
System.out.println("The sum is: " + sum);
// example_2 -> calculate area of rectangle
System.out.print("Enter the length of the rectangle: ");
float length = scanner.nextFloat();
System.out.print("Enter the width of the rectangle: ");
float width = scanner.nextFloat();
float area = length * width;
System.out.println("The area of the rectangle is: " + area);
// example_3 -> show user info
System.out.print("Enter your first name: ");
String firstName = scanner.next();
System.out.print("Enter your last name: ");
String lastName = scanner.next();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter your gender (Male/Female): ");
String gender = scanner.nextLine();
System.out.print("Enter your email address: ");
String email = scanner.nextLine();
System.out.println("\n--- User Information ---");
System.out.println("Full Name : " + firstName + " " + lastName);
System.out.println("Age : " + age);
System.out.println("Gender : " + gender);
System.out.println("Email : " + email);
// example_4 -> calculate average
System.out.print("Enter the student's full name: ");
String fullName = scanner.nextLine();
System.out.print("Enter marks for Subject 1: ");
float subject1 = scanner.nextFloat();
System.out.print("Enter marks for Subject 2: ");
float subject2 = scanner.nextFloat();
System.out.print("Enter marks for Subject 3: ");
float subject3 = scanner.nextFloat();
float average = (subject1 + subject2 + subject3) / 3;
System.out.println("\n--- Student Marks Summary ---");
System.out.println("Student Name: " + fullName);
System.out.println("Subject 1: " + subject1);
System.out.println("Subject 2: " + subject2);
System.out.println("Subject 3: " + subject3);
System.out.printf("Average Marks: %.2f", average);
}
}