为什么netbeans没有显示系统输出代码

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (93)

我正在NetBeans中创建一个预订项目,我首先实现了一个预订控制器,它将使用Java扫描程序验证用户输入。我想在终端中测试代码并输入数据。当我运行代码终端的输出时,终端只显示“Build successful”。并且显示没有任何系统打印出代码行。我不太确定代码有什么问题,请参阅下文

package fitnessclassapp;
import java.util.Scanner;
public class BookingController {       

   private Scanner input = new Scanner (System.in); 
   Customer customer = new Customer (); 

    // customer enter details and the details are validated   
    private String Customer () { 

        String customerName = ""; 
        int customerAge = -1 ; 
        String  membership  = ""; 
        boolean isName; 

        System.out.println( "Please enter your name " );
        do { 
            // name of condition HasNext will check the user input 
            if ( input.hasNext()) { 
                customerName = input.nextLine();
                isName = true; 

                // add a boolean 
            }else
                System.out.println ( "You have provided incorrect information");

            isName = false; 
            input.next(); 

        }while ( !isName ); 

        System.out.println(customerName); 

        return customerName; 
    }   
}
提问于
用户回答回答于

试试这个代码,

 package fitnessclassapp;
import java.util.Scanner;
public class BookingController { 
    private Scanner input = new Scanner(System.in);
//  Customer customer = new Customer();

    // customer enter details and the details are validated
    private String Customer() {

        String customerName = "";
        int customerAge = -1;
        String membership = "";
        boolean isName;

        System.out.println("Please enter your name ");
        do {
            // name of condition HasNext will check the user input
            if (input.hasNext()) {
                customerName = input.nextLine();
                isName = true;

                // add a boolean
            } else
                System.out.println("You have provided incorrect information");

            isName = false;
            input.next();

        } while (!isName);

        System.out.println(customerName);

        return customerName;
    }

    public static void main(String[] args) {
        BookingController con = new BookingController();
        con.Customer();
    }

}

扫码关注云+社区

领取腾讯云代金券