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

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助输入输出问题
needd





发贴: 55
积分: 0
于 2005-10-23 23:36 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
目的是
不停读取字母直到q的时候结束程序,

import java.io.*;
public class test{
  public static void main(String agrs[])throws IOException{
    char a='a';
    
    do
    {
      a=(char)System.in.read();
    }while(a=='q');
    
    System.exit(0);
    }
}

为何以上程序无法实现???



作者 Re:求助输入输出问题 [Re:needd]
hxz5830





发贴: 24
积分: 2
于 2005-10-24 09:13 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
needd wrote:
目的是
不停读取字母直到q的时候结束程序,

import java.io.*;
public class test{//首字母大写
  public static void main(String agrs[])throws IOException{
    char a='a';
    
    do
    {
      a=(char)System.in.read();
    }while(a=='q');//while(a!='q');
    
    System.exit(0);
    }
}


try to do



作者 Re:求助输入输出问题 [Re:needd]
fufejwq520





发贴: 1
积分: 0
于 2005-10-24 10:50 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
到q的时候不能结束啊


作者 Re:求助输入输出问题 [Re:needd]
JavaandC





发贴: 230
积分: 15
于 2005-10-24 12:33 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
import java.io.*;
public class test{
public static void main(String agrs[])throws IOException{
char a='a';

do
{
a=(char)System.in.read();
}while(a!='q'); //注意:这里不能写成while(a=='q');

System.exit(0);
}
}

这样读到q的时候,就会自动退出循环结束。



作者 Re:求助输入输出问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2005-10-24 13:06 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
确实如此
谢各位帮忙

再问一下,如果写成==是什么意思?



作者 Re:求助输入输出问题 [Re:needd]
bluecrystal





发贴: 2788991
积分: 48
于 2005-10-24 13:43 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
needd wrote:
确实如此
谢各位帮忙

再问一下,如果写成==是什么意思?


== 就是逻辑相等的意思
= 是赋值运算符

一定要区分
Smile



Just Software & Travel
-- 我的blog -- 技术点滴/经验分享
作者 Re:求助输入输出问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2005-10-24 14:40 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
斑竹,我意思是while(a=='q')程序流程是怎么回事???
程序是怎么走的?



作者 Re:求助输入输出问题 [Re:needd]
Jcat

熊猫的猫



发贴: 266
积分: 16
于 2005-10-24 15:14 user profilesend a private message to usersend email to Jcatsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1. while循环是(包括那三种循环都是):当判断表达式为true是继续循环,为false时跳出循环。
2.a=='q'当你输入的是非q时,结果是false,跳出循环。

do
{
a=(char)System.in.read();
System.out.print( a ); //加一句输出,你就能体会程序是怎么走的了
}while(a=='q');



编程,游泳,睡觉--SleepingCat
作者 Re:求助输入输出问题 [Re:needd]
leiqlion





发贴: 15
积分: 0
于 2005-10-24 21:14 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
当你的输入为q时,程序就循环执行,否则就要退出!


作者 Re:求助输入输出问题 [Re:needd]
needd





发贴: 55
积分: 0
于 2005-10-24 22:33 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
明白,谢了


作者 Re:求助输入输出问题 [Re:needd]
q_yuan





发贴: 174
积分: 3
于 2005-10-24 23:00 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
有意思的


作者 Re:求助输入输出问题 [Re:needd]
q_yuan





发贴: 174
积分: 3
于 2005-10-24 23:02 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
[iframe]有意思的[/iframe]


作者 Re:求助输入输出问题 [Re:needd]
q_yuan





发贴: 174
积分: 3
于 2005-10-24 23:05 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
[color = #000000]有意思的[/color]


作者 Re:求助输入输出问题 [Re:JavaandC]
wslss007





发贴: 35
积分: 0
于 2005-10-25 12:39 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
JavaandC wrote:
import java.io.*;
public class test{
public static void main(String agrs[])throws IOException{
char a='a';

do
{
a=(char)System.in.read();
}while(a!='q'); //注意:这里不能写成while(a=='q');

System.exit(0);
}
}

这样读到q的时候,就会自动退出循环结束。


这位兄弟有错,应该改成while(a='q'),而且后面没有;但是我这样运行了还是有错误,报错如下
d:\JCREAT~1\MyProjects\hi.java:11: 需要 ';'
System.exit(0)
^
1 错误
可我明明在System.exit(0)后面加了;奇怪



作者 Re:求助输入输出问题 [Re:needd]
JavaandC





发贴: 230
积分: 15
于 2005-10-26 12:53 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
to "wslss007":

我写的程序根本没有错误,希望你再看看书应该怎么写。

下面还是那个程序,我用Eclipse运行了很多遍,根本没有错误。

import java.io.*;
public class test{
public static void main(String agrs[])throws IOException{
char a='a';

do
{
a=(char)System.in.read();
}while(a!='q'); //注意:这里不能写成while(a=='q');

System.exit(0);
}
}


JavaandC edited on 2005-10-26 13:01

作者 Re:求助输入输出问题 [Re:needd]
revo1021





发贴: 4
积分: 0
于 2005-10-26 15:25 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
没有错误。。。


作者 Re:求助输入输出问题 [Re:needd]
hualee





发贴: 17
积分: 0
于 2005-10-30 15:37 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
我认为这是基本功的问题,要搞清楚do while 语句是先做然后再判断的。对于前面的例子是先给a赋值,然后做一个判断,看是否a不等于q,如果是,则再做上面的do否则下来做退出动作。流程是do if y->do/n->next.
如果是a='q'的话,你按照流程看看



作者 Re:求助输入输出问题 [Re:needd]
wslss007





发贴: 35
积分: 0
于 2005-10-31 12:44 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
明白了,朋友,不好意思,看错了。



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