Answer to Question #283723 in Java | JSP | JSF for Ifzal

Question #283723

Write a program to create two single dimension array to store the name and age of 20 persons. Then display the name and age of only those persons whose age is more than 40.


1
Expert's answer
2021-12-30T07:14:09-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		String personNames[] = new String[20];
		int personAges[] = new int[20];


		for (int i = 0; i < 20; i++) {
			System.out.print("Enter the name of person " + (i + 1) + ": ");
			personNames[i] = keyBoard.nextLine();
			System.out.print("Enter the age of person " + (i + 1) + ": ");
			personAges[i] = keyBoard.nextInt();
			keyBoard.nextLine();
		}
		System.out.println("The name and age of only those persons whose age is more than 40.");
		for (int i = 0; i < 20; i++) {
			if (personAges[i] > 40) {
				System.out.println(personNames[i] + " is " + personAges[i] + " years old");
			}
		}


		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog