第八周上机
public class fff
public class Rectangle { int length; int width; public void getPer() { System.out.println("矩形的周长=" + (length + width) * 2); } public void getArea() { System.out.println("矩形的面积=" + length * width); } public void showAll() { System.out.println("长=" + length); System.out.println("宽=" + width); getArea(); getPer(); } } package sdd; import java.util.Scanner; public class Tese { public static void main(String[] args) { // TODO Auto-generated method stub Rectangle a = new Rectangle(); Scanner input = new Scanner(System.in); System.out.print("请输入长:"); a.length = input.nextInt(); System.out.print("请输入宽:"); a.width = input.nextInt(); a.showAll(); } }
package Test; public class Bijiben { char yanse; int cpu; public void Showyanse() { System.out.println("笔记本颜色为:" + yanse+"色"); } public void Showcpu() { System.out.print("cpu型号是:" + cpu); } } package Test; public class sed { public static void main(String[] args) { // TODO Auto-generated method stub Bijiben a = new Bijiben(); a.yanse = '白'; a.cpu = 2020; a.Showyanse(); a.Showcpu(); } }
复制代码 package Test; public class Person { String name; int nianling; double shengao; int tizhong; public void sayHello() { System.out.println("Hello,my name is " + name); System.out.println(name + '、' + shengao + '、' + nianling + "岁"); } } package Test; public class Constructor { public static void main(String[] args) { // TODO Auto-generated method stub Person a = new Person(); a.name = "zhangsan"; a.shengao = 1.73; a.nianling = 33; a.sayHello(); Person b = new Person(); b.name = "lishi"; b.shengao = 1.74; b.nianling = 44; b.sayHello(); } }
{ int x; int y; Point() { System.out.println(x); System.out.println(y); System.out.println("调用后:"); } Point(int x0, int y) { x = x; y = y; System.out.println(x); System.out.println(y); } void movePoint(int dx, int dy) { dx = x + 100; dy = y + 100; System.out.println("p1的坐标为" + dx + "\n" + "p2的坐标为" + dy); } } package bbt; public class bbt { public static void main(String[] args) { // TODO Auto-generated method stub Point p=new Point(); p.x=100; p.y=200; p.movePoint(p.x,p.y); }