import java.util.*;
public double getDiscount(){
    Scanner input = new Scanner(System.in);
    double discount;
    int custNo = input.nextInt();
    if (custNo>2000 && custNo <= 4000)
        discount = 0.9;
    else if (custNo > 4000 && custNo <=6000)
        discount = 0.8;
    else if (custNo > 6000)
        discount = 0.7;
    else
        discount = 1;    return discount;}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zx521clc】截止到2008-06-24 12:44:20的历史汇总数据(不包括此帖):
    发帖数:0                  发帖分:0                  
    结贴数:0                  结贴分:0                  
    未结数:0                  未结分:0                  
    结贴率:-------------------结分率:-------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    你没有把方法写在类里面啊 
    import java.util.*;
    public class aaa{  public double getDiscount(){
        Scanner input = new Scanner(System.in);
        double discount;
        int custNo = input.nextInt();
        if (custNo>2000 && custNo <= 4000)
            discount = 0.9;
        else if (custNo > 4000 && custNo <=6000)
            discount = 0.8;
        else if (custNo > 6000)
            discount = 0.7;
        else
            discount = 1;    return discount;
      }  public static void main(String[] args){
        aaa a = new aaa();
    System.out.println(a.getDiscount());
      }
    }
      

  3.   

    这个是我从代码里截取的一段,是写在类里面的,但是我写到后面
    就是无法返回discount,是不是discount在if语句里的赋值不能
    调用出来返回回去
      

  4.   


    import java.util.*;public class AA { public double getDiscount() {
    Scanner input = new Scanner(System.in);
    double discount;
    int custNo = input.nextInt();
    if (custNo > 2000 && custNo <= 4000)
    discount = 0.9;
    else if (custNo > 4000 && custNo <= 6000)
    discount = 0.8;
    else if (custNo > 6000)
    discount = 0.7;
    else
    discount = 1; return discount; } public static void main(String[] args) {
    AA a = new AA();
    System.out.println(a.getDiscount());
    }
    }输入:123
    输出:1.0
      

  5.   

    谢谢!如果在if语句上面再加个for循环,内容是循环查询数组,还能return 
    discount吗?