
Java编程高手进~~!!帮个忙
题目:编写一个程序,从键盘不断地读取输入的字符,直到读到字符‘q‘,程序结束,提示:调用System.in.read()。下面是我编写的程序,大家帮忙看下哪里错了··帮忙...
题目:编写一个程序,从键盘不断地读取输入的字符,直到读到字符‘q‘,程序结束,提示:调用System.in.read()。
下面是我编写的程序,大家帮忙看下哪里错了··帮忙改下·(把改好的程序发上来)·很急,谢了@@@@!~~
class lesson2
{
public static void main(String [] args)
{
try
{
x=System.in.read();
}catch(Exception e){}
while(x!='q')
{
System.out.println((char)x);
x=System.in.read();
try
{
x=System.in.read();
}catch(Exception e){}
}
}
} 展开
下面是我编写的程序,大家帮忙看下哪里错了··帮忙改下·(把改好的程序发上来)·很急,谢了@@@@!~~
class lesson2
{
public static void main(String [] args)
{
try
{
x=System.in.read();
}catch(Exception e){}
while(x!='q')
{
System.out.println((char)x);
x=System.in.read();
try
{
x=System.in.read();
}catch(Exception e){}
}
}
} 展开
6个回答
展开全部
System.in.read(); 需要try catch。
还有就是。System.in.read()的结果应该是int型。而并没有见你声明你的x为int型
需要的第一个try外面声明一下。int x = 0;
还有就是。System.in.read()的结果应该是int型。而并没有见你声明你的x为int型
需要的第一个try外面声明一下。int x = 0;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class lesson2
{
public static void main(String[] args){
try{
System.out.print("Please input(End with q):");
int x = System.in.read();
while (x != 'q'){
System.out.print("\nYou Input is " + (char)x + " Please input next(End with q):");
x = System.in.read();
}
}catch{
}
}
}
{
public static void main(String[] args){
try{
System.out.print("Please input(End with q):");
int x = System.in.read();
while (x != 'q'){
System.out.print("\nYou Input is " + (char)x + " Please input next(End with q):");
x = System.in.read();
}
}catch{
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class lesson2 {
public static void main(String[] args) {
int x = 0;
try {
x = System.in.read();
} catch (Exception e) {
}
while (x != 'q') {
System.out.println((char) x);
try {
x = System.in.read();
} catch (Exception e) {
}
}
}
}
public static void main(String[] args) {
int x = 0;
try {
x = System.in.read();
} catch (Exception e) {
}
while (x != 'q') {
System.out.println((char) x);
try {
x = System.in.read();
} catch (Exception e) {
}
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
实现键盘输入不能这样的
最简单的是用Scanner
不然你就要用IO输入输出流 BufferedReader
和InputStreamReader
最简单的是用Scanner
不然你就要用IO输入输出流 BufferedReader
和InputStreamReader
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
char x='';
do
{
x=System.in.read();
}while(x!='q')
do
{
x=System.in.read();
}while(x!='q')
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询