Java基础题 求大神救救孩子
ProgrammingExercise:1)Writeashortprogramthatallowstheusertoinputapositiveintegerandth...
Programming Exercise:
1) Write a short program that allows the user to input a positive integer and then outputs a randomly generated integer between 1 and the input number. 展开
1) Write a short program that allows the user to input a positive integer and then outputs a randomly generated integer between 1 and the input number. 展开
1个回答
展开全部
import java.util.*;
public class Exam {
public static void main(String[] args) {
int n,b;
Scanner sc=new Scanner(System.in);
System.out.print("please input a integer:");
n=sc.nextInt();
b=new Random().nextInt(n)+1;
System.out.println(b);
sc.close();
}
}
public class Exam {
public static void main(String[] args) {
int n,b;
Scanner sc=new Scanner(System.in);
System.out.print("please input a integer:");
n=sc.nextInt();
b=new Random().nextInt(n)+1;
System.out.println(b);
sc.close();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询