代码如下:
第一种:
import java.util.Scanner;
public class Area {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入高度:");
double a=sc.nextDouble();
System.out.println("请输入宽度:");
double b=sc.nextDouble();
double c=a*b;
double d=2*(a+b);
System.out.printf("面积为:%.2f\n",c);
System.out.printf("周长为:%.2f\n",d);
}
}
第二种:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class Area {
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
try{
System.out.println("请输入高度:");
String changdu = br.readLine();
System.out.println("请输入宽度:");
String kuandu = br.readLine();
int a = Integer.parseInt(changdu);
int b = Integer.parseInt(kuandu);
double c=a*b;
double d=2*(a+b);
DecimalFormat df = new DecimalFormat("#.00");
System.out.println("面积为:"+df.format(c));
System.out.println("周长为:"+df.format(d));
}
catch(IOException e){
e.printStackTrace();
}
}
}
版权声明:本文为weixin_44286093原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。