Java *Please dont handwrite code* The attached java file is a short program that
ID: 3604290 • Letter: J
Question
Java *Please dont handwrite code*
The attached java file is a short program that implements a for loop. Add code to this program that implements a while loop for doing exactly the same thing as the provided for loop.
You will need to upload your .java file in answering this question.
public class Mid_Term_Loops {
/*
* Please provide the code for a while loop which does exactly the
* same thing as the below for loop.
*/
public static void main(String[] args) {
for(int i=22; i<=35; i++) {
System.out.println("counter: " + i);
}
}
}
Explanation / Answer
public class Mid_Term_Loops {
public static void main(String[] args) {
int i=22; //intialize i value as 22
while(i<=35){ // loop condition whether it is true the loop will continue otherwise terminate this loop
System.out.println("counter: " + i); // printing the i value
i++;// increment the i value
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.