调用函数或返回main方法

时间:2017-02-27 17:02:31

标签: java inheritance methods

在输入“' y'之后调用演示方法后

一次迭代后它应该再次要求继续吗? (是/否)请帮助!! Thnxx提前

public void demo()
        {
            System.out.println("Withdrawal or deposit? (w/d) :");
            char choice = s.next().charAt(0);
            System.out.println("Checking or Savings? (c/s) :");
            char choicetwo = s.next().charAt(0);
            System.out.println("Amount? : ");
            int amt = s.nextInt();
        }

  public static void main(String[] args)
    {
        Scanner  s = new Scanner(System.in);
        Child c = new Child();
        c.display();
        c.demo();
        System.out.println("Continue? : ");
        char input = s.next().charAt(0);
        while(input == 'y')
        {
            c.demo();
        }

2 个答案:

答案 0 :(得分:0)

您需要将变量赋值放入while循环中:

        System.out.println("Continue? : ");
        char input = s.next().charAt(0);
        while(input == 'y')
        {
            c.demo();
            System.out.println("Continue? : ");
            input = s.next().charAt(0);                
        }

答案 1 :(得分:0)

    System.out.println("Continue? : ");
    char input = s.next().charAt(0);
    while(input == 'y')
    {
    c.demo();
    System.out.println("Continue? : ");
    input = s.next().charAt(0);
    }