第5次作业--对象的创建与使用

矩形

 1 import java.util.*;
 2 public class T6 {
 3 
 4     public static void main(String[] args) {
 5         // TODO Auto-generated method stub
 6 
 7         Rectancle A;
 8         A = new Rectancle();
 9 
10         System.out.print("请输入矩形的宽和高");
11         Scanner in = new Scanner(System.in);
12         A.height = in.nextDouble();
13         A.width = in.nextDouble();
14         
15         System.out.println("矩形的面积为"+A.Carea(A.height,A.width));
16         System.out.println("矩形的周长为"+A.per(A.height,A.width));
17         
18     }
19     
20 }
21 
22 class Rectancle{
23     double height;
24     double width;
25     double area;
26     double perimeter;
27     
28     double Carea(double x,double y) {
29         return x*y;
30     }
31     double per(double x,double y) {
32         return 2*(x+y);
33     }
34     
35 }

 

阶乘

复制代码
 1 package f;
 2 public class Computer {
 3     public int sum = 1;
 4     public int fac(int x) {
 5         for(int i=1;i 
  
复制代码

 

App.java

复制代码
 1 import f.Computer;
 2 import java.util.*;
 3 public class App {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         System.out.println("输入一个整数");
 8         
 9         Scanner in = new Scanner(System.in);
10         int n = in.nextInt();
11         
12         Computer b = new Computer();
13         int num = b.fac(n);
14         
15         System.out.println(num);
16     }
17 
18 }
复制代码

 

你可能感兴趣的:(第5次作业--对象的创建与使用)