2017-02-04 95 views
-3
import java.util.*; 


public class LifeSimulator{ 

    static String name= var; 

    public static void Choice1(){ 

    } 


    public static void main(String[] args){ 

     Scanner input= new Scanner(System.in); 

     LifeSimulator player= new LifeSimulator(); 

     System.out.println("Welcome to Life Simulator 2017! What is your name?"); 

     player.name= input.nextLine(); 

     System.out.println("Hello"+name); 


} 
+0

什麼是'var',它在哪裏聲明? – nullpointer

回答

-1

這裏是你的更正後的代碼:

import java.util.Scanner; 

public class LifeSimulator { 

    static String name; 

    public static void Choice1() { 

    } 

    public static void main(String[] args) { 

     Scanner input = new Scanner(System.in); 
     LifeSimulator player = new LifeSimulator(); 
     System.out.println("Welcome to Life Simulator 2017! What is your name?"); 
     player.name = input.nextLine(); 
     System.out.println("Hello " + name); 

    } 

} 

希望這有助於。

+0

也試圖解釋你做了什麼改變,它會幫助別人。 –

0
Clear code is as below. 

import java.util.*; 

public class LifeSimulator { 
    static String name; 
    public static void main(String[] args) { 
     Scanner input = new Scanner(System.in); 
     System.out.println("Welcome to Life Simulator 2017! What is your name?"); 
     LifeSimulator.name = input.nextLine(); 
     System.out.println("Hello " + name); 
     input.close(); 
    } 
} 

Corrections 
1. Class is not closed with } 
2. Invalid variable assignment static String name= var; 
3. Unused method Choice1() 
4. static field name should be referred with class name LifeSimulator and not by it's object player.