Advertisement
Yee0418

Loops Q.2

Sep 11th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.36 KB | None | 0 0
  1. int balls = 1;
  2.  
  3. while(balls < 3){
  4.     if(balls == 1){
  5.         System.out.println("I have ball");
  6.     }
  7.     else if(balls == 0){
  8.         System.out.println("No balls :(");
  9.     }
  10.    
  11.     balls = (balls + 1)/balls;
  12. }
  13.  
  14. //What will this program print out?
  15.  
  16. // Because of integer division, the loop will never finish. This results in a stack-overflow error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement