Westonci.ca is the ultimate Q&A platform, offering detailed and reliable answers from a knowledgeable community. Discover comprehensive solutions to your questions from a wide network of experts on our user-friendly platform. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

It seems like no matter what I do this code is still giving me the error "
Program end never reached (commonly due to an infinite loop, infinite recursion, or divide/mod by 0).
Tests aborted"
import java.util.Scanner;
public class DivideByTwoLoop {
public static void main (String [] args) {
int userNum = 0;
userNum = 20;
while(userNum >= 1){ System.out.print(userNum + " ");
userNum = userNum/2;
}
if((userNum >1) && !(userNum ==0)){
System.out.print(userNum);
} else {
}
while(userNum !=0) System.out.print(userNum + " ");
System.out.println("");
return; }
}


Sagot :

Explanation:

I ran this on an online compiler with no issues, so I would try to use a different compiler if I were you. For example, sometimes the compiler can run a different program than the one you're currently on.

I would also recommend cleaning up the code. You don't need anything outside of the first part, as the latter 2 parts don't do anything because the number is already 0 by then.

Here's what I ended up with:

int userNum = 20;

       

       while(userNum >= 1){

           System.out.print(userNum + " ");

           userNum = userNum/2;

       }

       

       return;

My output is:

20 10 5 2 1

Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Thank you for visiting Westonci.ca. Stay informed by coming back for more detailed answers.