//compare 2 char with for loop
import java.util.Arrays;
class TestCheck{
public static void main (String args[]){
String str = "AB";
int len,len2;
char[] charArray = str.toCharArray();
char inputChar;
inputChar = 'A';
System.out.print("\n");
System.out.print("String is "+str);
System.out.print("\n");
System.out.print("\n");
for(int i = 0;i<charArray.length;i++){
System.out.println("char array is>>"+charArray[i]);
}
len = charArray.length;
System.out.println("length of char array is>>"+len);
System.out.print("\n");
System.out.println("input char is>> "+inputChar);
///////////////////////////////////////////////////////
//compare two arrayList
for(int index = 0;index<charArray.length;index++){
if(charArray[index] == inputChar){
System.out.println("index "+index+" equals");
}else{
System.out.println("index "+index+" not equals");
}
}
}
}
This code no error,but I want to declare method Check() for compare charArray and inputChar
I 'm niebie in java.I want some advice for declare method Check.
Thanks.
03-25-2008, 01:30 PM
Hack
Ok, you say you aren't getting any errors?
Do you get the right result when you run this?
03-26-2008, 12:01 AM
nspils
Some thoughts:
you can have your str for your class and pass in your inputChar as an agument to your checkChar( char inputChar ) method, then loop through your string to test if inputChar == str.charAt(index) ... return index if found or -1 if not found ...
also - you assign the value of length to len ... why aren't you using len as your loop sentinel rather than accessing your arrayList every loop?
04-01-2008, 03:20 PM
googgoo
Thank for that.
04-02-2008, 07:20 AM
Hack
Did what nspils post resolve your issue or do you still have questions?