2014-07-17 1 views
-4

내 코드에 도움이 필요합니다. 나는 자바의 멍청한 놈이지만 언젠가는 그 일에 정말로 잘할 수 있기를 희망한다. 내가 다른 비판하고 나는 그것이 알고 있기 때문에 이것은 nooby 작은 게임이라고하지 마십시오이?내 경우 엔 Else statement ... Im noob

if (random == r); 
    System.out.println("You Win! You get: $" + m); 
if (random != r); 
    System.out.println("You lose :(Try again?"); 

사이에 로그인 할 것 어떻게

static Scanner sc = new Scanner(System.in); 
    public static void main(String[] args){ 
     Lottery(); 
    } 

    public static void Lottery(){ 
     System.out.println("Welcome to Jacks Lottery!"); 
     System.out.println("If the Numbers match... You Win! It will pick a random number of the money you win!"); 
     int random = (int)(Math.random() * 50 + 1); 
     int r = (int)(Math.random() * 50 + 1); 
     int m = (int)(Math.random() * 1000 + 1); 
     System.out.println("The First Number is: " + random); 
     System.out.println("The Second Number is: " + r); 

     if (random == r); 
     System.out.println("You Win! You get: $" + m); 
     if (random != r); 
     System.out.println("You lose :(Try again?"); 
    } 
} 

. 나는 가족을 보여주고 그들을 깜짝 놀라게하는 재미있는 일을하고 있습니다. if

if (random == r); 

;에서 세미콜론

+2

을 변경할 수 있습니다 {'제어 흐름 문과 함께. 그것은 당신이 그것을 알지 못하는 사이에 당신의 목숨을 구할 것입니다. – Shail016

답변

2

삭제 명령문 그래서 다음 문장의 종료를 의미

ifelse 대신 (2)의 상태를 검사

if(condition) { 

} else { 

} 
1
전환없이 조건 실행 얻을 것이다
if (random == r){ 
    System.out.println("You Win! You get: $" + m); 
} 
else{ 
    System.out.println("You lose :(Try again?"); 
} 
2

끝 부분에 '{'no ';'

if (random == r){ 
     System.out.println("You Win! You get: $" + m); 
} 
else{ 
     System.out.println("You lose :(Try again?"); 
} 
1

if (random == r); // when your if condition match it will execute nothing 
        // since there is no code block between close) and ; 
    System.out.println("You Win! You get: $" + m); 

당신은 당신의 코드가 작동 이제

if (random == r) // remove ; 
    System.out.println("You Win! You get: $" + m); 

에 따라 사용할 수있는 다음 코드 라인을 고려하십시오. 좋은 연습이 if

if (random == r){ 
System.out.println("You Win! You get: $" + m); 
} 

에 대한 {}을 사용해야로는 자바 초보자하지만 다시 당신이 사용하는`중괄호 당신의 다음 코드도

if (random == r); 
    System.out.println("You Win! You get: $" + m); 
    if (random != r); 
    System.out.println("You lose :(Try again?"); 

이 수정 버전

if (random == r){ 
    System.out.println("You Win! You get: $" + m); 
    }else{  
    System.out.println("You lose :(Try again?"); 
    } 
+0

아플뿐입니다. "{":) – TheJavaDeveloper