while 문
class ExerciseCh4_5_3 {
public static void main(String[] args) {
int i = 0;
String s = new String("string");
char c='r'; int sw=0;
while (s.charAt(i) != ' ')
if ( c == s.charAt(i)) {
sw=1;
System.out.println(" Position of " + c + " = " + (i++));
break;
} else i++;
if (sw == 0)
System.out.println("Not found");
}
}
제가 고친 while -> for 문
class ExerciseCh4_5_3_1 {
public static void main(String[] args) {
int i = 0;
String s = new String("string");
char c='r';
for (int sw=0; s.charAt(i) != ' ' i++)
if ( c == s.charAt(i)) {
sw=1;
System.out.println("Position of" + c + " = " + (i++));
break;
} else
if (sw == 0)
System.out.println("Not found");
}
}
제가 고친 while -> do-while 문
class ExerciseCh4_5_3 {
public static void main(String[] args) {
int i = 0;
String s = new String("string");
char c='r'; int sw=0;
do{
if ( c == s.charAt(i)) {
sw=1;
System.out.println(" Position of " + c + " = " + (i++));
break;
} else i++;
if (sw == 0)
}while (s.charAt(i) != ' ')
System.out.println("Not found");
}
}
이상하게 계속 에러 뜨네요 -0-;;
아무리 고쳐도 잘 안되고 -_-
그냥 while 문을 for 과 do-while 로 할땐 되던데, if else 문이 껴 드니 전혀 못하겠음 -_-;;
기본이 안되서 그런지 흑흑 ㅜ_ㅜ