Charles Jacob Charles Jacob - 13 days ago 6
Java Question

Java how to jump back to While loop


So if large is not equal to count then large should increment until count and large have the same value the thing is after that my prof wants to Input a new integer again then it will loop again but i dont know how to make my code go back to while I NEED HELP ASAP Thankyousomuch!!


if (LARGE == Count)
{
System.out.println ("Large is Equal to Count");
}


while (Count != LARGE)
{
LARGE++;
System.out.println ("Large is " +LARGE);
}


if (LARGE == Count)
{
System.out.println ("Input a new integer to compare")
LARGE = input.newInt();
}

PVR PVR
Answer

As per my understanding this is what you want.

public static void main(String[] args) {

        int LARGE = 0;
        int Count = 0;
        String s = null;
        Scanner sc = new Scanner(System.in);
        do {

            LARGE = sc.nextInt();
            Count = sc.nextInt();

            if (LARGE == Count) {
                System.out.println("Large is Equal to Count");
            } else {
                do {
                    LARGE++;
                    System.out.println("Large is " + LARGE);
                } while (Count != LARGE);

                if (LARGE == Count) {
                    System.out.println("Large is Equal to Count");
                    System.out.println("Input a new integer to compare");
                }

            }

            System.out.println("Do you want to continue? If yes then Press Y");
            s = sc.next();
        } while (s.equalsIgnoreCase("Y"));

    }
Comments