初学java,请大家指点
解决方案 »
- java代码如何判断文件类型为execl2003和execl2007
- 如何将 Sting a = "TEST2008" 生成二进制文件
- 我做的挖地雷游戏在restart后一刷新button都不见了,但鼠标一放上去就出现了,放在哪儿那个键出来。请教各位。
- JAVA如何解析word编辑完成的.doc文档
- 在一个字符串中怎么判断是英文还是中文?
- super问题
- 关于jdk1.4.2 为何编译能通过?却不能之行呢?
- 关于package后图片找不到的问题
- 如何从数据库里取出blob对象?
- 大家给我出出主意
- 如何从WindosXP中将日志(应用程序、安全性和系统日志)提取出来,转换成EXCEL格式存储到一个数据库中
- 关于jtree添加节点
byte[]buf=new byte[512];
java.io.InputStream in=System.in;
try {
in.read(buf);
} catch (IOException e) {
e.printStackTrace();
}
res=new String(buf);
或者用流 不过麻烦点
System.out.print("请输入您的数据: ");int num=scanner.nextInt();System.out.pringtln(num);
boolean quitFlag = false ;
String lastLine ="" ;
BufferedReader stdin = null ;
System.out.println("输入exit来退出");
while (!quitFlag){
try{
stdin = new BufferedReader( new InputStreamReader(System.in));
lastLine = stdin.readLine() ;
}catch (IOException e){
e.printStackTrace();
}
if (lastLine.trim().toLowerCase().equals("exit".toLowerCase())) {
quitFlag = true ;
System.out.println("再见!");
System.exit(0);
}
System.out.println("你刚才输入了" +lastLine.lenght() +"字符");
}
}
byte[] b = new byte[100];
try{
System.out.in(b);
}catch(IOException ioe){
ioe.printStackTrace();
}
String s = new String(b);//把byte数组转换成字符串
s = s.trim();//消除前后空格那么s就是输入的字符串了.是不是觉得很麻烦,我个人觉得很麻烦,至于为什么,我也不知道.
java 1.5引进了Scanner类,在某种程度上解决了从标准输入的读入的问题。
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]);
}
}