Welcome to Westonci.ca, the place where your questions find answers from a community of knowledgeable experts. Our Q&A platform provides quick and trustworthy answers to your questions from experienced professionals in different areas of expertise. Get immediate and reliable solutions to your questions from a community of experienced professionals 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

Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Keep exploring Westonci.ca for more insightful answers to your questions. We're here to help.