为了账号安全,请及时绑定邮箱和手机立即绑定

类型开头非法(其他)

类型开头非法(其他)

凤凰求蛊 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 关注
  • 158 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信