Write a java program to read the names and ages of 10 people and print the name of the oldest person

Here's a Java program that reads the names and ages of 10 people and prints the name of the oldest person:

```java
import java.util.Scanner;

public class OldestPerson {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String[] names = new String[10];
int[] ages = new int[10];

for (int i = 0; i < 10; i++) {
System.out.println("Enter the name of person " + (i + 1) + ": ");
names[i] = scanner.nextLine();

System.out.println("Enter the age of person " + (i + 1) + ": ");
ages[i] = scanner.nextInt();
scanner.nextLine(); // Clear newline symbol left by nextInt
}

int oldestIndex = 0;
for (int i = 1; i < ages.length; i++) {
if (ages[i] > ages[oldestIndex]) {
oldestIndex = i;
}
}

System.out.println("The oldest person is: " + names[oldestIndex] + " with age of " + ages[oldestIndex] + " years.");
}
}
```

To run the program, save it in a file called `OldestPerson.java`, then compile and run it using these commands in the terminal:

```bash
javac OldestPerson.java
java OldestPerson
```

The program will prompt you to enter the names and ages of 10 people, and then print the name of the oldest person.

Sure! Here's a step-by-step guide to write a Java program that reads the names and ages of 10 people and prints the name of the oldest person:

Step 1: Create a Java class and import the necessary packages:
```java
import java.util.Scanner;
```

Step 2: Define the main method and initialize variables for storing the oldest person's name and age:
```java
public class OldestPersonFinder {
public static void main(String[] args) {
String oldestPersonName = "";
int oldestPersonAge = Integer.MIN_VALUE;
}
}
```

Step 3: Create a Scanner object to read user input:
```java
Scanner scanner = new Scanner(System.in);
```

Step 4: Use a for loop to read the names and ages of 10 people:
```java
for (int i = 1; i <= 10; i++) {
System.out.println("Enter name of person " + i + ":");
String name = scanner.nextLine();

System.out.println("Enter age of person " + i + ":");
int age = scanner.nextInt();
scanner.nextLine(); // Consume the newline character

// Compare ages and update values if current person is oldest
if (age > oldestPersonAge) {
oldestPersonAge = age;
oldestPersonName = name;
}
}
```

Step 5: Print the name of the oldest person:
```java
System.out.println("The oldest person is: " + oldestPersonName);
```

Step 6: Close the Scanner object:
```java
scanner.close();
```

Putting it all together, the complete Java program will look like this:

```java
import java.util.Scanner;

public class OldestPersonFinder {
public static void main(String[] args) {
String oldestPersonName = "";
int oldestPersonAge = Integer.MIN_VALUE;

Scanner scanner = new Scanner(System.in);

for (int i = 1; i <= 10; i++) {
System.out.println("Enter name of person " + i + ":");
String name = scanner.nextLine();

System.out.println("Enter age of person " + i + ":");
int age = scanner.nextInt();
scanner.nextLine(); // Consume the newline character

if (age > oldestPersonAge) {
oldestPersonAge = age;
oldestPersonName = name;
}
}

System.out.println("The oldest person is: " + oldestPersonName);

scanner.close();
}
}
```

That's it! Now you can compile and run the Java program to read the names and ages of 10 people, and it will print the name of the oldest person.

To write a Java program to read the names and ages of 10 people and print the name of the oldest person, you can follow the steps below:

1. Create a Java class and name it something like "OldestPersonFinder".
2. Declare an array to store the names of the people. Since we are going to read the names of 10 people, the array size can be 10. For example:
```java
String[] names = new String[10];
```
3. Declare another array to store the ages of the people. The size of this array will also be 10, corresponding to each person's age. For example:
```java
int[] ages = new int[10];
```
4. Use a loop to read the names and ages of the 10 people. You can utilize a `Scanner` class to get the input from the user. For example:
```java
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
System.out.print("Enter name of person " + (i+1) + ": ");
names[i] = scanner.nextLine();

System.out.print("Enter age of person " + (i+1) + ": ");
ages[i] = scanner.nextInt();
scanner.nextLine(); // to consume the newline character left by nextInt()
}
```
Note: Be sure to call `scanner.nextLine()` after reading an integer to consume the newline character left in the buffer.

5. Find the index of the oldest person by iterating through the ages array. For example:
```java
int oldestPersonIndex = 0;
for (int i = 1; i < 10; i++) {
if (ages[i] > ages[oldestPersonIndex]) {
oldestPersonIndex = i;
}
}
```
6. Print the name of the oldest person using the index found in the previous step. For example:
```java
System.out.println("The oldest person is: " + names[oldestPersonIndex]);
```
7. Finally, close the scanner to release system resources. For example:
```java
scanner.close();
```

That's it! You have now written a Java program to read the names and ages of 10 people and print the name of the oldest person. You can put all the code snippets together to complete the program.