Java 一个简单问题!

2024-11-18 06:15:45
推荐回答(3个)
回答1:

import java.util.Scanner;
public class Simpletest{
    public static void main(String args[]){
        System.out.println("Enter a digit! ");
        Scanner input = new Scanner(System.in);
        //输入数字
        int ok=input.nextInt();   
        if (ok < 9)
            System.out.println("Your answer is smaller than 9!");
        else if (ok == 9)
            System.out.println("Your answer is equal than 9!");
        else
            System.out.println("Your answer is bigger than 9!");
   }
}

回答2:

if (x<=9)
{
System.out.println("Enter a digit! ");
Scanner input = new Scanner(System.in);
int ok=input.nextInt();
System.out.println("Your answer is smaller than 9!");
}
加下面3行代码就行的 典型的if else语句的
else{
System.out.println("Your answer is bigger than 9!")


希望对你有所帮助

回答3:

import java.util.Scanner;
public class Simpletest{
public static void main(String args[]){
int x=9;
if (x<=9)
{
System.out.println("Enter a digit! ");
Scanner input = new Scanner(System.in);
int ok=input.nextInt();
System.out.println("Your answer is smaller than 9!");
}else{
System.out.println("Enter a digit! ");
Scanner input = new Scanner(System.in);
int ok=input.nextInt();
System.out.println("Your answer is bigger than 9!");
}