这个是我写的可是不对麻烦哪位兄弟帮我看看
public static void main(String[] args)throws java.io.IOException {
// TODO Auto-generated method stub
int a,b;
System.out.print("请输入第一个数: ");
a= System.in.read();
System.out.print("请输入第二个数: ");
b=System.in.read();
System.out.print("两个数相乘的值为:"+a*b);
}
public static void main(String[] args)throws java.io.IOException {
// TODO Auto-generated method stub
int a,b;
System.out.print("请输入第一个数: ");
a= System.in.read();
System.out.print("请输入第二个数: ");
b=System.in.read();
System.out.print("两个数相乘的值为:"+a*b);
}
public static void main(String[] args)throws java.io.IOException {
// TODO Auto-generated method stub
int a,b;
System.out.print("请输入第一个数: "+a);
a= System.in.read();
System.out.print("请输入第二个数: "+b);
b=System.in.read();
System.out.print("两个数相乘的值为:"+a*b);
}
public class A
{
public static void main(String[] args)
{
int a = Integer.valueOf(args[0]).intValue();
int b = Integer.valueOf(args[1]).intValue();
System.out.println(a*b);
}
}执行的时候:
java A args[0] args[1]
args[0] args[1]你要输入的2个整数
所以你可以在main函數里這樣寫
System.out.print("輸入兩個數值,并以空格分隔\n");
String c="";
BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
c=s.readLine();
String[] st =c.split(" ");
add(st);
然后在add方法里面寫入你的算法 public void add(String[] string)
{
int x=0;
Iterator itr;
ArrayList alist=new ArrayList();
for(int i=0;i<string.length;i++)
{
alist.add(string[i]);
}
itr=alist.iterator();
while(itr.hasNext())
{
x=Integer.parseInt((String)itr.next());
sum+=x;
}
}
System.in.read()只读取了一个字符,所有LZ的程序应该不能考虑两位数的乘法,
4楼的方法可以试一下,
LZ还可以试用一下Scanner类,用Scanner.nextInt()或Integer.parseInt(Scanner.nextLine());
看看帮助文档,就知道Scanner怎么用了,很简单的.