亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型開頭非法(其他)

類型開頭非法(其他)

鳳凰求蠱 2023-11-01 22:07:42
我正在為我的 CS 110 課程做一個實驗,有一行代碼無法編譯。我確保它與參考材料上的模板相匹配。我不確定重現該問題需要多少代碼,因此我提供了所有代碼并 //ed 出現問題的位置。更具體地說,它位于第 42 行。錯誤顯示“錯誤:類型非法開始”。我已經嘗試刪除一些我認為多余的括號,但彈出了更多錯誤。/* Author: Collin Walsh   Date: 10/15/2019   File name: NstedIfs.java*/import java.util.Scanner;public class NestedIfs {    //main    public static void main(String[] args) {        Scanner keyboard = new Scanner (System.in);        double outsideTempF;        System.out.println("What is the temperature outside? Input a value and press enter ");        outsideTempF =  keyboard.nextDouble();        Scanner input = new Scanner (System.in);        int raining = 0;        System.out.println("If it is raining, enter the number 1. Then press enter");        raining = keyboard.nextInt();        //indicate what clothing to wear, based on temp           if (outsideTempF > 70) {            if (raining == 1) {                System.outprintln("Wear t-shirt, shorts, sandals, and an unbrella");            }else{                      System.out.println("Wear t-shirt, shorts, and sandals.");            }           } else if (outsideTempF <= 30) {            if (raining == 1)                System.out.println("Wear boots, pants, raincoat, and gloves.");            } else {                //for any temperature beolow 30                System.out.println("Wear boots, pants, sweater, and gloves.");            }        } else { //this is where the error occurs             if (raining == 1) {                System.out.println("Wear long-sleeve shirt, pants, a raincoat, and shoes");            } else {                System.out.println("Wear long-sleeve shirt, pants, and shoes");            }        }    }
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

本來應該是這樣的:


/* Author: Collin Walsh

Date: 10/15/2019

File name: NstedIfs.java

*/


import java.util.Scanner;


public class NestedIfs {


    // main

    public static void main(String[] args) {


        Scanner keyboard = new Scanner(System.in);


        double outsideTempF;


        System.out.println("What is the temperature outside? Input a value and press enter ");


        outsideTempF = keyboard.nextDouble();


        Scanner input = new Scanner(System.in);


        int raining = 0;


        System.out.println("If it is raining, enter the number 1. Then press enter");


        raining = keyboard.nextInt();


        // indicate what clothing to wear, based on temp

        if (outsideTempF > 70) {

            if (raining == 1) {

                System.out.println("Wear t-shirt, shorts, sandals, and an unbrella");

            } else {

                System.out.println("Wear t-shirt, shorts, and sandals.");

            }

        } else if (outsideTempF <= 30) {

            if (raining == 1) {

                System.out.println("Wear boots, pants, raincoat, and gloves.");

            } else {

                // for any temperature beolow 30

                System.out.println("Wear boots, pants, sweater, and gloves.");

            }

        } else {

            if (raining == 1) {

                System.out.println("Wear long-sleeve shirt, pants, a raincoat, and shoes");

            } else {

                System.out.println("Wear long-sleeve shirt, pants, and shoes");


            }

        }

    }

}

其中一個牙套有問題,其中一個System.out.println缺少一個點,所以它是System.outprintln


查看完整回答
反對 回復 2023-11-01
  • 1 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號