system.in输入流到底是怎么用的? 我想从键盘输入两个数,然后存在int a;和int b;中.应该怎么写啊?能更详细的讲下System.in的用法更好啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*; public class Test{ public static void main(String[] args) { FileInputStream fileIn = null; FileOutputStream fileOut = null; PrintWriter pw = null; BufferedReader br = null; try{ fileIn = new FileInputStream(new File(args[0])); fileOut = new FileOutputStream(new File(args[1])); br = new BufferedReader(new InputStreamReader(fileIn)); pw = new PrintWriter(new OutputStreamWriter(fileOut)); String s = null; while((s = br.readLine())!=null) { System.out.println(s); s = s.replaceAll(",",",\n"); pw.write(s); } } catch(ArrayIndexOutOfBoundsException e) {e.printStackTrace();} catch(IOException e) {e.printStackTrace();} finally{ try { pw.flush(); br.close(); pw.close(); } catch (IOException e) { e.printStackTrace(); } } } } System.in属于Java的标准输入流,因为输入流可以包括一个文件,键盘输入,更或是一个其他的输入流等,System.in就属于控制台输入流,键盘输入是一种System.in流 简单把System.in包装到就行了.多看APIBufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String inputStr = br.readLine(); 你把键盘看着是文件,和文件一样的操作.帮我看看我的贴:AWT-EventQueue-0 "是个什么东西 50 buyiwangzi 刚发的. import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class TestExample { public static void main(String []args) throws IOException { int a,b; String str; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); str=br.readLine(); a=Integer.parseInt(str); str=br.readLine(); b=Integer.parseInt(str); System.out.println("a="+a+" "+"b="+b); }} 只能是把输入的数先存成String类型?然后用Integer.parseInt或者Double.parseDouble等再把它转换过来吗?比如我我只让他输入数字,输入别的我报错,然后就把输入的直接存在int类型中?能不能这样??? import java.util.Scanner;public class Stdin { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); String s=sc.next(); System.out.println("a+b="+(a+b)); System.out.println(s); }} 多看API 手册 很有帮助 System.in 是 Scanner包中的方法 主要用于从键盘上读取数据例如: Scanner sc=new Scanner(System.in); int m=sc.next.Int(); System.out.println(m); 请教关于httpclient的问题 怎么使用UNICODE码呢?? 关于super的问题 在java中怎么把字符串输出到.txt文本文件中,并占用给定的列宽! 打包的问题 JTree的各项值变化了以后,如何让它重画? 画图坐标 XP应安装什么版本的JDK 菜鸟问题--怎么引用这个变量? 求一个java代码 高手帮忙,要求,再定义一个ClassOne类,并调用Studnts的studentNum()方法。该怎么做? javazscript在IE中执行不了
public class Test
{
public static void main(String[] args)
{
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
PrintWriter pw = null;
BufferedReader br = null;
try{
fileIn = new FileInputStream(new File(args[0]));
fileOut = new FileOutputStream(new File(args[1])); br = new BufferedReader(new InputStreamReader(fileIn));
pw = new PrintWriter(new OutputStreamWriter(fileOut)); String s = null;
while((s = br.readLine())!=null)
{
System.out.println(s);
s = s.replaceAll(",",",\n");
pw.write(s);
}
}
catch(ArrayIndexOutOfBoundsException e)
{e.printStackTrace();}
catch(IOException e)
{e.printStackTrace();}
finally{
try
{
pw.flush(); br.close(); pw.close();
}
catch (IOException e)
{
e.printStackTrace();
} }
}
}
多看API
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = br.readLine();
和文件一样的操作.
帮我看看我的贴:
AWT-EventQueue-0 "是个什么东西
50 buyiwangzi 刚发的.
import java.io.IOException;
import java.io.InputStreamReader;public class TestExample {
public static void main(String []args) throws IOException
{
int a,b;
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
System.out.println("a="+a+" "+"b="+b);
}
}
import java.util.Scanner;public class Stdin { public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
String s=sc.next();
System.out.println("a+b="+(a+b));
System.out.println(s);
}}
例如:
Scanner sc=new Scanner(System.in);
int m=sc.next.Int();
System.out.println(m);