我的循环阻止我获得预期的输出吗?

时间:2016-11-06 03:03:03

标签: java

我的目标是为一对整数确定第二个整数是否是第一个整数的倍数。我的代码如下:

import java.util.Scanner;

    public class Multiples {

        public static void main(String [] args) {

            boolean run = true;

            while(run) {

                Scanner input = new Scanner(System.in);

                System.out.print("Enter one number:");
                int num1 = input.nextInt();
                System.out.print("Enter a second number:");
                int num2 = input.nextInt();

            boolean result = isMultiple(num1, num2);

            if(result) {
                System.out.println(num2 + " is a multiple of " + num1);

            } else {
                System.out.println(num2 + " is not a multiple of " + num1);

            }

                System.out.print("Do you want to enter another pair(y/n)?");
                run = YesOrNo(input.next());
            }        
        }

            public static boolean YesOrNo(String a) {

                if(a.equals("y"))
                    return true;
                else
                    return false;
            }


            public static boolean isMultiple (int x , int y) {
                 if(y % x == 0)
                     return true;   
                 else
                     return false;

            }      
        }

这是我的输出: enter image description here

这是预期的输出: enter image description here

预期的输出令我感到困惑。

0 个答案:

没有答案