关于import java.io.*;
public class Ab
{
public static void main(String args[]) throws IOException
{
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println(“请输入a值”);
String s=input.readLine();
double a=Double.parseDouble(s);
System.out.println(“请输入b值”);
s=input.readLine();
double b=Double.parseDouble(s);
System.out.println(“交换前a=”+a+”,b=”+b);
a=t;t=b;b=a;
System.out.println(“交换后a=”+a+”,b=”+b);
}
}的问题
首先:t 变量没有声明:double t = 0;
然后:算法错了:
应为:
t = a;
a = b;
b = t;
给你改过的源码自己看看。
import java。io。*;
public class Ab
{
public static void main(String args[]) throws IOException
{
InputStreamReader reader = new InputStreamReader(System。
in);
BufferedReader input = new BufferedReader(reader);
System。out。println(“请输入a值”);
String s=input。readLine();
double a=Double。
parseDouble(s);
System。out。println(“请输入b值”);
s=input。readLine();
double b=Double。parseDouble(s);
double t = 0;
System。
out。println(“交换前a=”+a+”,b=”+b);
t = a;
a = b;
b = t;
System。out。println(“交换后a=”+a+”,b=”+b);
}
}。