问大家一个简单的问题

pittzhao 2006-05-18 02:26:48
问一个简单的程序, 实现功能是 根据用户传入的一个数字 随机产生两个 大于0 小于传入数字的 数字 ,有什么好的算法没有,我写了一个 总觉得并不是最好,来看看大家的实现。
...全文
106 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lookhang 2006-05-18
  • 打赏
  • 举报
回复
import java.io.*;
class Getchar{
public static void main(String args[])throws IOException
{
for(;;)
{
System.out.print("Iuput:");

int i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
int y = Integer.parseInt(s);
if(y==1 || y==0)
{
System.out.println("Check ur input!>>>");
continue;
}
while(i!=2)
{
int r=(int) (Math.random()*y);
if(r!=0)
{
System.out.println(r);
i++;
}
}
System.out.println("------------------------------");
}
}
}
believefym 2006-05-18
  • 打赏
  • 举报
回复
Random.nextInt(input)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧