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(); } }
二
三.例题