I'm begineer so i simply write this code. Got error help me do some correction thanks
Are you try to tell us is use the element to check the index is same or not right???
import java.util.Scanner;
/**
*
* @author Louis
*/
public class testing {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in); //For scanner
String[] arr1 = {"a","b","c","d"}; //array list
int[] arr2 = {5,6,2,9};
int first=0,second=0; // use to temporary store index
//let user want to compare which index
System.out.println("Please enter arr1 :");
String a = scan.next();
System.out.println("Please enter arr2 :");
int b = scan.nextInt();
for(int x=0;x<arr2.length;x++){
if(a.equals(arr1[x])){
first = x; // the index of arr1
}
else{
System.out.println("Out of range!!");
}
if(b == x){
second = x; // the index of arr2
}
else{
System.out.println("Out of range!!");
}
}
//here is to check the index is same or not.. same will be true !!
boolean answer=false;
if(first == second){
answer = true;
}
else{
answer=false;
}
System.out.println("The arr1 "+first+ " and arr2 "+second+" same index :"+answer);
}
}
** I'm begineer for the java .. if got problem help me correction post it here.. Thank you^^