首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎么输入字符串,并输出

2012-02-26 
如何输入字符串,并输出如何输入字符串,并输出或者赋值给变量[解决办法]Scanner sc new Scanner(System.i

如何输入字符串,并输出
如何输入字符串,并输出或者赋值给变量

[解决办法]
Scanner sc = new Scanner(System.in);
String str = sc.next();
System.out.println(str);
[解决办法]
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
try{
System.out.println(br.readLine());
}catch(Exception e){}
[解决办法]
import java.io.*;

class Test {
public static void main(String args[]) {
char ch[]=new char[60];
int i=0,j;
System.out.print( "please input: ");
/*请输入字符串,直到回车结束*/
while( (ch[i]=(char)System.in.read())!= '\n ')
i++;
/*输出字符串*/
for(j=0;j <=ch.length-1;j++)
System.out.print(ch[j]);

}
}

热点排行
Bad Request.