We appreciate your visit to I am coding in Java and trying to figure out how to get an output that shows from 20 to 1 using a do while. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!

I am coding in Java and trying to figure out how to get an output that shows from 20 to 1 using a do-while loop. Please show how I can do that in Java. Thank you!

This is what I have so far:

```java
class Main {
public static void main(String[] args) {
int d = 20;
do {
System.out.println(d);
d--;
} while (d >= 1);
}
}
```

The output I need is:

```
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
```

Answer :

You can achieve the desired output of counting from 20 to 1 using a do-while loop in Java.

The Updated Code

Here's an updated version of your code that will produce the expected output:

class Main {

public static void main(String[] args) {

int d = 20;

do {

System.out.println(d);

d--;

} while (d >= 1);

}

}

In this code, the loop starts with d initialized to 20. It prints the value of d, then decrements it by 1 (d--) within each iteration. The loop continues executing as long as d is greater than or equal to 1 (d >= 1). This way, it will print the numbers from 20 down to 1, exactly as you need.


Read more about Java code here:

https://brainly.com/question/25458754
#SPJ4

Thanks for taking the time to read I am coding in Java and trying to figure out how to get an output that shows from 20 to 1 using a do while. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!

Rewritten by : Barada