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!
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!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada