자바 카드번호 맞추기 게임 소스코드 질문요! ㅠ
반율하
Q:숨겨진 카드의 수를 맞추는 게임을 만들어보자. 0~99까지의 임의의 수를 가진 카드를 한 장 숨기고 이 카드의 수를 맞추는 게임이다.
제가 쓴 코드인데요... 문제는 직접 실행해보시면 알겠지만 카드 번호를 못 맞출 경우 카드 수보다 높거나 낮을 때 다시 한번 입력할 때 더 이상 진행하지 않는건데요... 어떻게 해야 하죠?
import java.util.Scanner;
import java.util.Random;
public class T {
public static void main(String[] args){
Scanner s=new Scanner(System.in);
Random r=new Random();
int k=r.nextInt(100);
int c;
String ys;
System.out.println(수를 결정하였습니다. 맞추어보세요\n);
c=s.nextInt();
L:
if(c==k){
System.out.println(맞았습니다.);
System.out.println(다시하시겠습니까(y/n));
ys=s.next();
while(ys==y){
k=r.nextInt(100);
System.out.println(수를 결정하였습니다. 맞추어보세요\n);
c=s.nextInt();
break L;
}
System.exit(0);
}
else{
while(c!=k){
if(ck){
System.out.println(더 낮게);
c=s.nextInt();
break L;
}else if(ck){
System.out.println(더 높게);
c=s.nextInt();
break L;
}else{}
}
}
}
}
-
한길찬
자바에는 goto문이 없습니다. while문 하나에 if else로 입력받은 숫자를 검사하면 됩니다.