java学习50天2020/8/24

import java.util.Scanner;
public class Rectangle {
    private int length; //矩形的长
    private int width;  //矩形的宽
     public Rectangle() {
     }
     public Rectangle(int length, int width) {
        this.length = length;
         this.width = width;
    }
     public void area() {
         int s;
         s=length*width;
         System.out.println("矩形面积:"+s);
     }
     public static void main(String[] args) {
         Scanner in=new Scanner(System.in);
         int a,b;
         System.out.print("请输入矩形的长和宽:");
         a=in.nextInt();
         b=in.nextInt();
         Rectangle r=new Rectangle(a,b);
         r.area();
     }
 }

 

 

 

public class DataType {
    private char s; 
    private int a;   
    private double b; 
    public DataType() {
    }
     public DataType(char s, int a, double d) {
         this.s = s;
         this.a = a;
        this.b = d;
     }
     public void display() {
         System.out.println("字符型:"+s);
        System.out.println("整型:"+a);
         System.out.println("浮点型:"+b);
     }
     public static void main(String[] args) {
         DataType p=new DataType('s',5,5.2);
         p.display();
     }
 }

 

 

三.例题

posted @ 2020-08-24 20:28  小强哥in  阅读(108)  评论(0编辑  收藏  举报