现在的推荐的输入方法是什么?
带参数的构造器怎么由用户输入数据?

解决方案 »

  1.   

    Scanner in = new Scanner(System.in);
    double dou = in.nextDouble();
    //前提是jdk1.5以上
      

  2.   

    Scanner scan = new Scanner(System.in);
    double d = scan.nextDouble();
      

  3.   

    就像ls2位一样。
    要求,jdk1.5以上
      

  4.   

    就像ls3位一样。 
    要求,jdk1.5以上
      

  5.   


    public class food {
    double dosage;
    String foodtype;
    public food(double adosage,String afoodtype){
    dosage=adosage;
    foodtype=afoodtype;
    }
    public boolean valdosage()
    {
    if(dosage<=100&&dosage>0){return true;}
    else{return false;}
    }
    public boolean valfoodtype()
    {
    if(foodtype=="WormSoup"||foodtype=="ButterflyWings"||foodtype=="BeetleJuice"){
    return true;
    }
    else{
    return false;
    }
    }
    }
      

  6.   

    import java.util.Scanner;
    public class test1 {
    public static void main(String args[]){
    double testdosage;
    String testfoodtype;
    Scanner reader=new Scanner(System.in);
    testdosage=reader.nextDouble();
    Scanner reader1=new Scanner(System.in);
    testfoodtype=reader1.next();
    food testfood=new food(testdosage,testfoodtype);
    System.out.println(testfood.valdosage());
    System.out.println(testfood.valfoodtype());

    }}
      

  7.   

    构造器的作用就是初始化成员变量,还有就是创建对象的功能,当你new一个对象的时候后面都是跟的构造方法,如果你的构造方法带有参数,用户在创建对象的时候就可以在new后面的构造方法中直接加入参数。我是这么理解的不知道对不对
      

  8.   

    昨天说我发贴太快不让发了
    我把结果发上来
    32.25
    WormSoup
    true
    false
    我怎么能使最后一个是true