import java.util.Scanner; /** * 输入长方形长和宽,计算周长 */ public class learnDemo4 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("长:"); double a= sc.nextDouble();//输入长 System.out.print("宽:"); double b= sc.nextDouble();//输入宽 // zc(a,b);//public static void zc(double a,double b) System.out.println("长为"+a+"\t"+"宽为"+b+"\t"+"长方形周长为"+zc(a,b));//public static double zc(double a,double b) } //无返回值 /*public static void zc(double a,double b){ double c=(a+b)*2; System.out.println("长为"+a+"\t"+"宽为"+b+"\t"+"长方形周长为"+c); }*/ //有返回值 由double zc 可知返回值类型为duoble public static double zc(double a,double b){ double c=(a+b)*2; return c;//返回值为c } }
Java学习 输入长方形长和宽,计算周长
最新推荐文章于 2023-11-27 15:21:50 发布