Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:求助一题 [Re:xxyxq163]
long_5281





发贴: 5
积分: 0
于 2007-11-09 09:54 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我来贴个命令行的:
public class InputMain {

public static void main(String[] args){
DataInputStream in = null ;
InputMain main = new InputMain();
try{
System.out.print("are you ready(y/n):");//是否准备好答题
in = new DataInputStream(System.in);
String readStr = in.readLine();
if(readStr!=null&&!"".equals(readStr)){//判断输入的字符串是否为空
if(readStr.equalsIgnoreCase("y")){ //开始答题
while(true){
int[] struts = main.getRandoms();
outer:
for(;trueWink{
main.showStruts(struts);
String readStr1 = in.readLine();
if(readStr1!=null&&!"".equals(readStr1)){ //判断输入的答案字符串是否为空
if(readStr1.equalsIgnoreCase("quit")){ //如果输入的是QUIT则退出程序
System.exit(0);
}
int src = Integer.parseInt(readStr1);//将字符串转换为整数
int value = main.getValue(struts[0],struts[1]); //获取题目的正确答案
if(main.isTrue(value,src)){ //判断输入的答案与正确答案是否相符
System.out.println("Very good!");
break outer; //如果答题正确则重新出题
}else{
System.out.println("No. Please try again.");
}
}
}
}
}else if(readStr.equalsIgnoreCase("n")){ //退出答题
System.exit(0);
}
}
if(in!=null) in.close(); //关闭输入流
}catch(IOException e){
System.out.println("系统运行出现异常:"+e.getMessage());
}
}

/**
* 获取随机正数数组
* @return
*/
public int[] getRandoms(){
int[] rands = new int[2];
rands[0] = (int) (Math.random()*100) ;
rands[1] = (int) (Math.random()*100) ;
return rands ;
}

/**
* 获取两正数乘积
* @param m
* @param n
* @return
*/
public int getValue(int m,int n){
return m*n;
}

/**
* 判断输入的答案与正确答案是否相符
* @param value
* @param src
* @return
*/
public boolean isTrue(int value,int src){
return value==src;
}

/**
* 显示题目
* @param randoms
*/
public void showStruts(int[] randoms){
System.out.print(randoms[0]+"*"+randoms[1]+"=?");
}
}




话题树型展开
人气 标题 作者 字数 发贴时间
9145 求助一题 xxyxq163 1385 2007-07-26 19:50
6743 Re:求助一题 hubmygirl 1670 2007-09-12 00:12
6807 Re:求助一题 JiafanZhou 125 2007-11-11 08:11
6506 Re:求助一题 long_5281 2733 2007-11-09 09:54

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923