如果除数不均匀分配,如何将代码重新启动到第一个输入?还有关于代码的任何指针要进一步发展吗?

时间:2015-09-26 04:12:03

标签: java loops

我会将所有代码都放在一个大循环中吗?如果是这样,我该怎么做?我读到我可以将开头标记为循环并使用底部的继续关键字? 也可以有人告诉我为什么当我运行代码并输入2个整数(即3和9)并且除数为3时它返回:33456678

package loop;

import java.util.*;

public class MinilabLoopLogic
{
    public static void main(String[ ] args)
    {
            int number1;
            int number2;
            int divisor;


        Scanner kb = new Scanner(System.in);  //you do it!



                System.out.print("Please enter 2 integers (separated by spaces): ");
                number1 = kb.nextInt();
                number2 = kb.nextInt();

                if (number1 < number2)  {      

        System.out.println("\n\nThis program will generate numbers BETWEEN "
                + number1 + " " +  number2);
                }



                else {
                    System.out.println("\n\nThis program will generate numbers BETWEEN " 
                           + number2 + " " + number1);
                        }

        System.out.print("\nPlease enter the integer your output should be divisible by: ");
                divisor = kb.nextInt();

                if (number1 < number2){
                   for (int i = number1 + 1; i < number2; i++ ){
                      System.out.print(i);
                      if (i % divisor == 0){
                        System.out.print(i);

                      }
                       else 

                          }


                }

0 个答案:

没有答案