2016-01-19 33 views
1

的方法首先發布在這裏!JAVA- NETBEANS-返回一個代碼爲

所以我有這段代碼:

static boolean getInternationalCalls() { 
    Scanner intercalls = new Scanner(System.in); 
    System.out.println("Would the customer like International Calls to be included within their minutes?"); 
    System.out.println("If yes, please enter Y, if no please enter N below."); 

    Scanner scanner = new Scanner(System.in); 

    if (scanner.next().equalsIgnoreCase("Y") || scanner.next().equalsIgnoreCase("yes")) { 
     System.out.println("Internatinal Calls will be included"); 
    } else if (scanner.next().equalsIgnoreCase("N") || scanner.next().equalsIgnoreCase("no")) { 
     System.out.println("International Calls will not be included"); 
    } else { 
     System.out.println("Invalid character, please enter Y or N"); 

    } 

困惑自己,不知道怎麼寫的return語句

將其返回到:

布爾interCalls = getInternationalCalls();

在此先感謝! :)

+0

[返回從方法中值(https://docs.oracle.com/ JavaSE的/教程/ JAVA/javaOO/returnvalue.html) – MadProgrammer

回答

0

我希望這不是你的功課傑米。你的方法錯過了很多東西,並有語法錯誤。請使用像eclipse這樣的IDE,並且會更容易。

static boolean getInternationalCalls() { 
     Scanner intercalls = new Scanner(System.in); 
     System.out.println("Would the customer like International Calls to be included within their minutes?"); 
     System.out.println("If yes, please enter Y, if no please enter N below."); 

     Scanner scanner = new Scanner(System.in); 
     String input = null; 
     while (true) { 
      input = scanner.next(); 
      if (input != null && (input.equalsIgnoreCase("Y") || input.equalsIgnoreCase("yes"))) { 
       System.out.println("Internatinal Calls will be included"); 
       return true; 
      } else if (input != null && (input.equalsIgnoreCase("N") || input.equalsIgnoreCase("no"))) { 
       System.out.println("International Calls will not be included"); 
       return false; 
      } else { 
       System.out.println("Invalid character, please enter Y or N"); 

      } 
     } 

    } 
0

我得到了它的工作:

靜態布爾getInternationalCalls(){ 布爾internationalCalls = FALSE; System.out.println(「客戶是否願意將國際電話納入其分鐘內?」); System.out.println(「如果是,請輸入Y,否則請在下面輸入N。」);

Scanner scanner = new Scanner(System.in); 

    if (scanner.next().equalsIgnoreCase("y") || scanner.next().equalsIgnoreCase("yes")) { 
     System.out.println("Internatinal Calls will be included"); 
    } else if (scanner.next().equalsIgnoreCase("n") || scanner.next().equalsIgnoreCase("no")) { 
     System.out.println("International Calls will not be included"); 
    } else { 
     System.out.println("Invalid character, please enter Y"); 

    } 
    return internationalCalls; 

沒有,哈哈

方項目的一切我已經介紹了在課堂上結合到目前爲止