类型开头非法(其他)

我正在为我的 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");

            }

        }

    }


凤凰求蛊
浏览 159回答 1
1回答

catspeake

本来应该是这样的:/* Author: Collin WalshDate: 10/15/2019File name: NstedIfs.java*/import java.util.Scanner;public class NestedIfs {&nbsp; &nbsp; // main&nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; Scanner keyboard = new Scanner(System.in);&nbsp; &nbsp; &nbsp; &nbsp; double outsideTempF;&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("What is the temperature outside? Input a value and press enter ");&nbsp; &nbsp; &nbsp; &nbsp; outsideTempF = keyboard.nextDouble();&nbsp; &nbsp; &nbsp; &nbsp; Scanner input = new Scanner(System.in);&nbsp; &nbsp; &nbsp; &nbsp; int raining = 0;&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("If it is raining, enter the number 1. Then press enter");&nbsp; &nbsp; &nbsp; &nbsp; raining = keyboard.nextInt();&nbsp; &nbsp; &nbsp; &nbsp; // indicate what clothing to wear, based on temp&nbsp; &nbsp; &nbsp; &nbsp; if (outsideTempF > 70) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (raining == 1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear t-shirt, shorts, sandals, and an unbrella");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear t-shirt, shorts, and sandals.");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } else if (outsideTempF <= 30) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (raining == 1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear boots, pants, raincoat, and gloves.");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // for any temperature beolow 30&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear boots, pants, sweater, and gloves.");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (raining == 1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear long-sleeve shirt, pants, a raincoat, and shoes");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Wear long-sleeve shirt, pants, and shoes");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}其中一个牙套有问题,其中一个System.out.println缺少一个点,所以它是System.outprintln
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java