您好我正在尝试运行一个简单的Odd偶数程序,但它给了我错误"标识符预期"程序如下:
import.java.io.*;
public class OddevenbufferedReader {
System.output.println("Enter a number to be checked as odd or even: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String args[]) {
int num, output;
num = Integer.parseInt(br.readLine());
output = num % 2;
if (output == 0) {
System.out.println("Entered number is even");
} else {
System.out.println("Entered number is odd");
}
}
}
答案 0 :(得分:0)
删除.
和import
java.io.*;
import java.io.*;
并将System.output.println
和BufferedReader br
行放在main
方法中。
答案 1 :(得分:0)
您的计划存在多个问题
导入语法不正确。
import.java.io.*;
应该是
import java.io.*;
System.output
应该更正
System.output.println("Enter a number to be checked as odd or even: ");
应该是
System.out.println("Enter a number to be checked as odd or even: ");
主要方法
public static void main(String args[]) {
System.out.println("Enter a number to be checked as odd or even: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num, output;
try {
num = Integer.parseInt(br.readLine());
output = num % 2;
if (output == 0) {
System.out.println("Entered number is even");
} else {
System.out.println("Entered number is odd");
}
} catch (NumberFormatException | IOException e) {
e.printStackTrace();
}
}