IN JAVA PLEASE
How many times does the while loop execute for the given input values of -1 4 0 9
userNum=3;while
(userNum>0){
//Do something
//Get usernum firm input
}
//TestCode.java import java.util.Scanner; public class TestCode { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int userNum=3; while (userNum>0){ System.out.println("Inside loop"); userNum = scan.nextInt(); } } }
Loop runs if the value of userNum is greater than 1
So, it runs for once because userNum is 3
Then userNum will be -1
So, comes out of the loop
So, answer is 1
1
Get Answers For Free
Most questions answered within 1 hours.