help what am i doing wrong While loop Description: In this activity you will learn how to use a while loop. You will pri

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

help what am i doing wrong While loop Description: In this activity you will learn how to use a while loop. You will pri

Post by answerhappygod »

help what am i doing wrong
While loop
Description:
In this activity you will learn how to use a while loop. You
will print all the numbers from x to 6 (x being a mystery number).
You can assume x is always a larger number than 6. Please follow
the steps below:
Steps:
Test:
Use the test provided.
Sample output:
If x was 10.
10
9
8
7
6
code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//--------------------------------------------------------
// Ignore. This is just used to get a mystery number
for x.
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number in the console
above 6.");
int x = sc.nextInt();
sc.close();
//--------------------------------------------------------
// Use a while loop to print the values of x to 6
decreasing in size by 1 each time.
while(-1);{
// Your code here:
System.out.println("x");
if (x<=10)
break;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply