import java.util.Scanner;
public class TestJT {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入整数");
int input= sc.nextInt();
if(input>=0){
System.out.println("你输入的是正数");
}else{
System.out.println("你输入的是负数");
}
}
import java.util.Scanner;
public class TE {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入一个整数");
int str = input.nextInt();
boolean flag = false;
do {
if (str >= 0) {
System.out.println("你输入的是正数" + " " + str);
flag = true;
} else if (str < 0) {
System.out.println("你输入的是负数" + " " + str);
flag = true;
} else {
System.out.println("输入错误");
continue;
}
} while (!flag);
}
}
关键片段
Scanner cin=new Scanner(System.in);//需要import一个包
int a=cin.nextInt();
if(a>0) System.out.println("a>0");
if(a<0) System.out.println("a<0");
别的部分就不啰嗦了