大内密探唐马儒
2015-09-02 11:18
package com.imooc; import java.util.Scanner; public class Rectangle extends Base { private static double chang; private static double kuan; public Rectangle() { // TODO Auto-generated constructor stub Scanner input = new Scanner(System.in); System.out.println("请输入长:"); chang = input.nextDouble(); System.out.println("请输入宽:"); kuan = input.nextDouble(); input.close(); } @Override public void zhouchang() { // TODO Auto-generated method stub double zhouchang = 2*chang+2*kuan; System.out.println("周长是:"+zhouchang); } @Override public void mianji() { // TODO Auto-generated method stub double mianji = chang * kuan; System.out.println("面积是:"+mianji); } }
package com.imooc; import java.util.Scanner; public class Initial { public static void main(String[] args) { // TODO Auto-generated method stub Initial o = new Initial(); o.sw(); } public void sw(){ System.out.println("请输入你要选择计算的形状:"); System.out.println("1、矩形 2、圆形"); Scanner input = new Scanner(System.in); int temp = input.nextInt(); switch(temp){ case 1: Base Rec = new Rectangle(); Rec.zhouchang(); Rec.mianji(); break; case 2: Base Cir = new Circle(); Cir.zhouchang(); Cir.mianji(); break; default: System.out.println("输出出错退出!"); break; } } }
input.close(); 这条语句的作用是什么呢?
为什么这么写?
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题