日期:2014-05-20 浏览次数:20601 次
import java.util.*; public class Beltandmethod { private static final int old = 20;//年纪 private String name ;//姓名 private int height ;//身高 private int weight ; //体重] Scanner sc = new Scanner (System.in); public void input (String name,int height,int weight){ this.name=name; this.height=height; this.weight=weight; System.out.println("请输入姓名:"); name=sc.next(); System.out.println("请输入身高:"); height=sc.nextInt(); System.out.println("请输入体重:"); weight=sc.nextInt(); } public void show (){ System.out.println("姓名是:"+name+" 身高是:"+height+" 体重是:"+weight+" 年龄是:"+old); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Beltandmethod center =new Beltandmethod (); String name = ""; int height= 0 ; int weight = 0 ; center.input(name, height, weight); center.show(); } }
public void input (String name,int height,int weight){ this.name=name; this.height=height; this.weight=weight; System.out.println("请输入姓名:"); this.name=sc.next(); System.out.println("请输入身高:"); this.height=sc.nextInt(); System.out.println("请输入体重:"); this.weight=sc.nextInt(); }
------解决方案--------------------
public void input (String name,int height,int weight){ System.out.println("请输入姓名:"); name=sc.next(); System.out.println("请输入身高:"); height=sc.nextInt(); System.out.println("请输入体重:"); weight=sc.nextInt(); //先把值读进来,在赋值嘛 this.name=name; this.height=height; this.weight=weight; }
------解决方案--------------------