Prompt: Create a multidimensional array. The array will store afirst and last na
ID: 3615322 • Letter: P
Question
Prompt: Create a multidimensional array. The array will store afirst and last name.Ask the user to enter 4 first and last names and store them intothe array.
Ask the user to input a first name. Search the array for thisname. When the name is located print the first and lastname.
Sample output.
Enter a first name:john
Enter a last name:smith
Enter a first name:hayden
Enter a last name:wimmer
Enter a first name:sam
Enter a last name:white
Enter a first name:rich
Enter a last name:goldman
Enter a first name to search for:rich
rich goldman _________________________________________________________________________________________ Here is what I have so far:
import java.util.Scanner;
public class MultiNameArray { public static void main(String[] args) { String firstName, lastName, searchName; Scanner scan = new Scanner (System.in); int[][] size = new int [4][2]; System.out.println ("Enter 4 first and last names"); for (int count = 0; count <= size.length; count++) { System.out.print ("Enter in first name: "); firstName = scan.nextLine(); System.out.print ("Enter in last name: "); lastName = scan.nextLine(); } System.out.print ("Enter in the name you want to search for:"); searchName = scan.nextLine(); if (searchName < size.length) { System.out.print(); } } } Prompt: Create a multidimensional array. The array will store afirst and last name.
Ask the user to enter 4 first and last names and store them intothe array.
Ask the user to input a first name. Search the array for thisname. When the name is located print the first and lastname.
Sample output.
Enter a first name:john
Enter a last name:smith
Enter a first name:hayden
Enter a last name:wimmer
Enter a first name:sam
Enter a last name:white
Enter a first name:rich
Enter a last name:goldman
Enter a first name to search for:rich
rich goldman _________________________________________________________________________________________ Here is what I have so far:
import java.util.Scanner;
public class MultiNameArray { public static void main(String[] args) { String firstName, lastName, searchName; Scanner scan = new Scanner (System.in); int[][] size = new int [4][2]; System.out.println ("Enter 4 first and last names"); for (int count = 0; count <= size.length; count++) { System.out.print ("Enter in first name: "); firstName = scan.nextLine(); System.out.print ("Enter in last name: "); lastName = scan.nextLine(); } System.out.print ("Enter in the name you want to search for:"); searchName = scan.nextLine(); if (searchName < size.length) { System.out.print(); } } }
Explanation / Answer
please rate-thanks import java.util.Scanner; public class untitled { public static void main(String[] args) { String searchName; boolean found=false; int i; Scanner scan = new Scanner (System.in); String[][] name = new String [4][2]; System.out.println ("Enter 4 first and last names"); for (int count = 0; countRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.