public class Admin {
public static void main(String[] args) {
Scanner in = new Scanner(System.in)
int x = in.nextInt()
int y = x
if (x >= 1 &&x <10) {
y = 3 * x - 2
} else if (x >= 10) {
y = 4 * x
}
System.out.println(y)
}
}
import java.util.Scannerpublic class Test {
public static void main(String srag[]){
int num = 0
while(true){
System.out.println("请输入一个正整数:")
Scanner sc = new Scanner(System.in)
num = sc.nextInt()
if(num>=0) break
}//如果输入的为正整数,跳出循环
System.out.println(num + "!=" + jc(num))
}
static int jc(int a){
if(a==1) return 1
else{
return a*jc(a-1)
}
} //递归法求阶乘
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)