第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

輸入菜單屏幕方法始終返回 0

輸入菜單屏幕方法始終返回 0

慕俠2389804 2022-11-02 16:58:56
我被分配創(chuàng)建一個(gè)菜單驅(qū)動(dòng)程序,其中包含一個(gè)顯示菜單屏幕/獲取用戶輸入的功能,但displaymenu()始終且僅返回 0 而不是新輸入的數(shù)字。我對(duì)編程很陌生,我用谷歌搜索了我能想到的所有東西,但我很困惑。import java.util.Scanner;public class menuDriven{   public static void main(String[] args)   {      int menuSelection=0;      double inches, centimeters, feet, meters, miles, kilometers;      Scanner keyboard = new Scanner(System.in);      displayMenu(keyboard, menuSelection);      switch(menuSelection)      {      case 1:         inchesToCentimeters(keyboard);         break;      case 2:         feetToMeters(keyboard);         break;      case 3:         milesToKilometers(keyboard);         break;      }   } // end main   public static int displayMenu(Scanner keyboard,  int menuSelection)    {   System.out.println("1. Convert inches to centimeters");   System.out.println("2. Convert feet to meters");   System.out.println("3. Convert miles to kilometers");   System.out.println();   System.out.println("Enter your selection");   menuSelection = keyboard.nextInt();    while (menuSelection < 1 || menuSelection > 3)      {         System.out.println("Please enter 1, 2, or 3.");         menuSelection = keyboard.nextInt();      }   return menuSelection;   }   public static void inchesToCentimeters(Scanner keyboard)   {      double inches, centimeters;      System.out.print("Enter the number of inches: ");      inches = keyboard.nextDouble();      centimeters = inches * 2.54;      System.out.println("That is equal to " + centimeters + " centimeters.");   }   public static void feetToMeters(Scanner keyboard)   {      double feet, meters;      System.out.println("Enter the number of feet: ");      feet = keyboard.nextDouble();      meters = feet * 0.3048;      System.out.println("That is equal to " + meters + " meters.");   }程序應(yīng)該接受用戶輸入 1、2 或 3,然后將該數(shù)字帶到開關(guān)并顯示代碼。
查看完整描述

2 回答

?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

Java 按值傳遞原始參數(shù),因此盡管您在 in 中操作menuSelection參數(shù)displayMenu,但menuSelectioninmain保持與調(diào)用之前相同displayMenu。


您可以將結(jié)果分配displayMenu給menuSelection:


menuSelection = displayMenu(keyboard, menuSelection);

您還可以刪除menuSelection作為參數(shù)的傳遞并在內(nèi)部聲明它displayMenu,例如:


public static int displayMenu(Scanner keyboard) {

    int menuSelection=0;


    //...

}


查看完整回答
反對(duì) 回復(fù) 2022-11-02
?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

嘗試這個(gè):


import java.util.Scanner;


public class menuDriven{

 public static void main(String[] args)

 {

    Scanner keyboard = new Scanner(System.in);


    displayMenu(keyboard);


} // end main


private static void displayMenu(Scanner keyboard)

{


    System.out.println("1. Convert inches to centimeters");

    System.out.println("2. Convert feet to meters");

    System.out.println("3. Convert miles to kilometers");

    System.out.println();


    System.out.println("Enter your selection");

    int menuSelection = keyboard.nextInt();

    while (menuSelection < 1 || menuSelection > 3)

    {

        System.out.println("Please enter 1, 2, or 3.");

        menuSelection = keyboard.nextInt();

    }

    switch(menuSelection)

    {

        case 1:

            inchesToCentimeters(keyboard);

            break;


        case 2:

            feetToMeters(keyboard);

            break;


        case 3:

            milesToKilometers(keyboard);

            break;

    }

    /* return menuSelection; */

}


private static void inchesToCentimeters(Scanner keyboard)

{

    double inches, centimeters;

    System.out.print("Enter the number of inches: ");

    inches = keyboard.nextDouble();

    centimeters = inches * 2.54;

    System.out.println("That is equal to " + centimeters + " centimeters.");


}


private static void feetToMeters(Scanner keyboard)

{

    double feet, meters;

    System.out.println("Enter the number of feet: ");

    feet = keyboard.nextDouble();

    meters = feet * 0.3048;

    System.out.println("That is equal to " + meters + " meters.");

}


private static void milesToKilometers(Scanner keyboard)

{

    double miles, kilometers;

    System.out.println("Enter the number of miles: ");

    miles = keyboard.nextDouble();

    kilometers = miles * 1.609;

    System.out.println("That is equal to " + kilometers + " kilometers.");

 }

} // end class



查看完整回答
反對(duì) 回復(fù) 2022-11-02
  • 2 回答
  • 0 關(guān)注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)