回车被认为是B了。 DataInputStream dis=new DateInputStream(System.in); 不行啊 我编译了一下会出现错误 cannot resolve symbol symbol : class DateInputStreamnew DateInputStream(System.in);这样的写法有错吧
byte[] aa = new byte[2000]; int num = System.in.read(aa); num是读到的byte总数。只要你一行输入不超过2000个byte就能保存在aa里面 你可以再定义一个bb = new byte[num];就可以了。
try { System.out.print("请输入a:"); byte[] aa = new byte[300]; a = System.in.read(aa); //a = System.in.read(); System.out.print("请输入b:"); byte[] bb = new byte[300]; b = System.in.read(bb); //b = System.in.read(); System.out.println("a="+a+" ,b="+b); System.out.println("和为:"+dd(a,b)); }catch(IOException e) { System.out.println("wrong"); };是不是要这样写? 可运行不成功请输入a:4 请输入b:6 a=2 ,b=2 和为:4 为什么?
1要用 bufferdReader 2 要将类型转化 string 转化成 int
public static void main(String[] args) { try { int nFirst = 0; int nSecond = 0; String sFirst,sSecond; BufferedReader in = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Please input the first number:"); sFirst = in.readLine();
感谢大家的帮忙,问题总算解决了。 谢谢各位! 代码整理如下: import java.io.*; import java.io.IOException; public class add { public static void main(String[] args) { System.out.println("Hello World!"); try { int nFirst = 0; int nSecond = 0; String sFirst,sSecond; BufferedReader in = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Please input the first number:"); sFirst = in.readLine();
read(byte[] b)
改成readln吧
DataInputStream dis=new DateInputStream(System.in);
不行啊
我编译了一下会出现错误
cannot resolve symbol
symbol : class DateInputStreamnew DateInputStream(System.in);这样的写法有错吧
那就只有自己判断了
用read(),一次读一个,然后凑起来
在你输入一个数后,按 enter key 时,己输入了b,b=enter 的编码
你在d=System.in.read(); 后 insert System.out.println(*a=*+a+*b=*);
观察结果
int num = System.in.read(aa);
num是读到的byte总数。只要你一行输入不超过2000个byte就能保存在aa里面
你可以再定义一个bb = new byte[num];就可以了。
System.out.print("请输入a:");
byte[] aa = new byte[300];
a = System.in.read(aa);
//a = System.in.read();
System.out.print("请输入b:");
byte[] bb = new byte[300];
b = System.in.read(bb);
//b = System.in.read();
System.out.println("a="+a+" ,b="+b);
System.out.println("和为:"+dd(a,b));
}catch(IOException e) {
System.out.println("wrong");
};是不是要这样写?
可运行不成功请输入a:4
请输入b:6
a=2 ,b=2
和为:4
为什么?
2 要将类型转化 string 转化成 int
{
try
{
int nFirst = 0;
int nSecond = 0;
String sFirst,sSecond;
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
System.out.print("Please input the first number:");
sFirst = in.readLine();
try
{
nFirst = Integer.parseInt( sFirst );
}
catch(NumberFormatException nfe )
{
System.out.println("错误的参数:"+sFirst);
System.exit(-1);
}
System.out.print("Please input the second number:");
sSecond = in.readLine();
try
{
nSecond = Integer.parseInt( sSecond );
}
catch(NumberFormatException nfe )
{
System.out.println("错误的参数:"+sSecond);
System.exit(-1);
}
int nTotal = nFirst + nSecond;
System.out.println("The added value is:"+ nTotal);
}
catch(IOException ie)
{
System.out.println( ie );
}
}
是什么?怎么用?
谢谢各位!
代码整理如下:
import java.io.*;
import java.io.IOException;
public class add
{
public static void main(String[] args)
{
System.out.println("Hello World!");
try
{
int nFirst = 0;
int nSecond = 0;
String sFirst,sSecond;
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
System.out.print("Please input the first number:");
sFirst = in.readLine();
try{
nFirst = Integer.parseInt( sFirst );
}
catch(NumberFormatException nfe )
{
System.out.println错误的参数:"+sFirst);
System.exit(-1);
}
System.out.print("Please input the second number:");
sSecond = in.readLine();
try{
nSecond = Integer.parseInt( sSecond );
}
catch(NumberFormatException nfe )
{
System.out.println错误的参数:"+sSecond);
System.exit(-1);
}
int nTotal = nFirst + nSecond;
System.out.println("The added value is:"+ nTotal);
}catch(IOException ie)
{
System.out.println( ie );
}
}
}