java学习48天2020/8/22

import java.util.Scanner;
public class dog {
	private int weight;
	private	 int age;
	public dog(int a,int b)
	{
	weight=a;age=b;
 }
    public void set_weight(int m)
	 {weight=m; }
	public void set_age(int n)
		 {
		  age=n;
		 }
	public int get_weight()
		 {
		  return weight;
		 }
	public int get_age()
		 {
		  return age;
		 }
	public static void main(String []args)
	{
		dog a=new dog(10,3);
		System.out.println("体重:"+a.get_weight()+"年龄:"+a.get_age());
		 int m,n;
		 System.out.println("重新输入体重和年龄:");
		 Scanner input=new Scanner(System.in);
		 m=input.nextInt();n=input.nextInt();
		 a.set_weight(m);a.set_age(n);
		 System.out.println("体重:"+a.get_weight()+"年龄:"+a.get_age());
	}

}

 

三例题

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