2017-05-13 62 views
0

我对java很新,因为我只是在昨天开始的,我正在尝试做一个小游戏,其中随机数被生成,你必须尝试猜测这个数字。我现在遇到的问题是没有任何东西会出现在控制台中。我不确定是什么导致了这个问题,因为它可能是我使用的代码或解释器。这里是你们检查的代码。让我知道我做错了什么,如果你能找到解决办法,谢谢。这段代码为什么不打印任何内容给控制台?

import java.util.Scanner; 
public class Random 

{ 
    int Ran = (int) Math.floor(Math.random() * 9); 
    Scanner input = new Scanner(System.in); 
    int Num = input.nextInt(); 
    public static void main(String[] args){} 
    {System.out.println("Geuss a number and see if it is correct!"); 
    } 
    { 
     if (Num == Ran) 
     {System.out.println("Correct! The number was " + Ran); 
     } 
     else{ 
      System.out.println("You are wrong!"); 
     } 
     } 
    public void If(boolean b) {} 
    } 

回答

0

你有空{}

public static void main(String[] args){ 
System.out.println("Geuss a number and see if it is correct!"); 
    } 

而且不写IF的功能。如果是本地编码中的本地表达。 已经有if子句试图给出唯一的名称。

import java.util.Scanner; 
    public class Random 

{ 
int Ran = (int) Math.floor(Math.random() * 9); 
Scanner input = new Scanner(System.in); 
int Num = input.nextInt(); 
public static void main(String[] args) 
{ 
    System.out.println("Geuss a number and see if it is correct!"); 
    if (Num == Ran) 
    {System.out.println("Correct! The number was " + Ran); 
    } 
    else{ 
     System.out.println("You are wrong!"); 
    } 
} 
} 
0

试试这个。

import java.util.Scanner; 
    public class Random 
    { 
     int Ran = (int) Math.floor(Math.random() * 9); 
     Scanner input = new Scanner(System.in); 
     int Num = input.nextInt(); 
     public static void main(String[] args){ 
      System.out.println("Geuss a number and see if it is correct!"); 
      if (Num == Ran) 
      {System.out.println("Correct! The number was " + Ran); 
      } 
      else{ 
       System.out.println("You are wrong!"); 
      } 
     } 
     public void If(boolean b) {} 
     } 
    } 
相关问题