+ 1
String arr[ ];
In java how to finde a String array(index number) by equaling with int ? int a=6; if(String arr[i]==a){}
6 Answers
+ 1
I am trying to catch array indexs value by entering a number
int choice =sc.nexInt();
String arr[]={"java","c","c++"};
for(int i=0;i<arr.length;i++){
If(choice==arr[i]){
System.out.print(arr[i]);
}
}
+ 2
AB Rahman "Mamnoon"
choice is integer
And arr[i] is string then how you can compare?
How number will be equal to string?
If you want index value then compare with index like (choice == i)
If you want index then you should enter string to get index by comparing with equals method.
like (choice.equals(arr[i]))
+ 2
AB Rahman "Mamnoon"
If you want a value on a particular index then why don't pass index value directly like this:
System.out.print(arr[choice]);
+ 2
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt(); //debug
String arr[]={"java","c","c++"};
for(int i=0;i<arr.length;i++){
if(choice==i){ //debug đ¤
System.out.print(arr[i]);
}
}
+ 1
Scanner sc = new Scanner(System.in);
String arr[]={"java","c","c++"};
int choice =sc.nexInt();
System.out.println(arr[choice]);
0
What you want to trying to do?