简单版~ import javax.swing.*; public class Fun{ public static void main(String arg[]){ int x=Integer.parseInt(JOption.showInputDialog("enter width:"); int y=Interger.parseInt(JOpiont.showInputDialog("enter height:"); JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y); } }要写异常,和其他的MM我
mport javax.swing.*; public class Fun{ 楼上: public static void main(String arg[]){ int x=Integer.parseInt(JOption.showInputDialog("enter width:");//1 int y=Interger.parseInt(JOpiont.showInputDialog("enter height:");//2 JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);//3 } 错误: 1.JOption->JOptionPane 2.Interger->Integer,JOption->JOptionPane 3.JOption->JOptionPane
好多错误,我改正后如下:import javax.swing.*; public class Fun{ public static void main(String arg[]){ double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:")); double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:")); JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y); } }
import javax.swing.*; public class Fun{ public static void main(String arg[]){ double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:")); double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:")); JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y); } }这个好,我一般都用JOptionPane.showInputDialog,不用BufferedReader,不知道哪个好点,另外LZ的代码不必写得那么复杂。
import java.io.*;
public class Changfangxing{
public static void main(String[] args){
float length,width;
String s1,s2;
BufferedReader bu1,bu2;
try{
System.out.print("请输入长方形的长:");
bu1=new BufferedReader(new InputStreamReader(System.in));
s1=bu1.readLine();
System.out.println();
System.out.print("请输入长方形的宽:");
bu2=new BufferedReader(new InputStreamReader(System.in));
s2=bu2.readLine();
System.out.println();
}
catch(IOException e){
System.out.println("不是数字型");
return;
}
length=Float.parseFloat(s1);
width=Float.parseFloat(s2);
System.out.println("长方形的面积为:"+length*width);
System.out.println("长方形的周长为:"+2*(length+width)); }
}
还有float通常精度有问题的,不如用double
import javax.swing.*;
public class Fun{
public static void main(String arg[]){
int x=Integer.parseInt(JOption.showInputDialog("enter width:");
int y=Interger.parseInt(JOpiont.showInputDialog("enter height:");
JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
}
}要写异常,和其他的MM我
public class Fun{
楼上:
public static void main(String arg[]){
int x=Integer.parseInt(JOption.showInputDialog("enter width:");//1
int y=Interger.parseInt(JOpiont.showInputDialog("enter height:");//2
JOption.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);//3
}
错误:
1.JOption->JOptionPane
2.Interger->Integer,JOption->JOptionPane
3.JOption->JOptionPane
public class Fun{
public static void main(String arg[]){
double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:"));
double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:"));
JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
}
}
public class Fun{
public static void main(String arg[]){
double x=Double.parseDouble(JOptionPane.showInputDialog("enter width:"));
double y=Double.parseDouble(JOptionPane.showInputDialog("enter height:"));
JOptionPane.showMessageDialog(null,"周长:"+2*(x+y)+"\n"+"面积:"+x*y);
}
}这个好,我一般都用JOptionPane.showInputDialog,不用BufferedReader,不知道哪个好点,另外LZ的代码不必写得那么复杂。