Hi guys I have two arrays and I want to ask the user to enter a code which is from the first array but I want the print out to say a detail from the second array, finding it hard to explain so this is a small sample of code that should be enough to show the issue I am having.
I know my for loop is wrong here because it prints out all the array. But what I want is say if I type: 5am
I want the print out to say "cheverolet is the chosen manufacturer".
import java.util.Scanner;
public class testing {
/**
* @param args
*/
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
final String[] CAR_CODE = { "1j", "2am", "3j",
"4am", "5am"};
final String[] CAR_NAMES = { "Toyota",
"Ford", "Subaru",
"Dodge",
"cheverolet"};
System.out.println("enter one of these codes: 1j; 2am; 3j; 4am; 5am ");
String code = kb.nextLine();
for (int i = 0; i < CAR_CODE.length; i++)
if (code.equalsIgnoreCase(CAR_CODE[i])) {
}
for (int i = 0; i < CAR_NAMES.length; i++)
System.out.println( CAR_NAMES[i]+" is the chosen manufacturer");
}
}
I know my for loop is wrong here because it prints out all the array. But what I want is say if I type: 5am
I want the print out to say "cheverolet is the chosen manufacturer".