我正在为我的 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");
}
}
}
catspeake
相关分类