this is my very first post ever here. I am VERY new at programming, started learning java like a week ago, but its very exciting so far.
I would like to hear your feedback on this code. Basically i want it to output the abbreviation of the state name, after inputting the name and visa versa...
Is there a more efficient way to write this? (Efficient as in least time for the machine to process the code)
import java.util.Scanner;
class apples2{
public static void main(String[] args){
Scanner inputStateName = new Scanner(System.in);
System.out.println("Input the state name or abbreviation: ");
String stateName = inputStateName.nextLine();
for(int counter = 0; counter <= statedata.states.length; counter++){
if(stateName.equalsIgnoreCase(statedata.states[counter])){
System.out.println("The abbreviation of your state is: " + statedata.statesAb[counter]);
break;
}
if(stateName.equalsIgnoreCase(statedata.statesAb[counter])){
System.out.println("You've entered an abbreviation, the state for that is: " + statedata.states[counter]);
break;
}
}
}
}
"statedata.states" is an array of all state names in another class and "statedata.statesAb" is an array of the abbreviations.