Access Millions of academic & study documents

Examine the following program and thoroughly explain what Is wrong wi

Content type
User Generated
Showing Page:
1/1
Examine the following program and thoroughly explain
what Is wrong with the code. The program should print the
values 1 through 10. Rewrite the code inside the main
method so it works correctly while maintaining the basic
structure of the provided code (l.e., don\'t rewrite the code
as a for loop or a/while loop). The rewritten code you
provide should be able to compile cleanly and perform the
stated task. public class Question { public static void
main(String[] args) { int counter; while (counter
Solution
public class Question //Here class name is
Qusetion { public static void main ( String arg[] )throws
IOException //we need to provide square barces to
arguments and we should throws input output exceptions {
int x=0,counter=1; // we should initialize the integer value x
to zero while(counter<=10) //setting counter value up to 10
{ x++; // incrementing value of x by 1 at each time
System.out.println(counter is now #d \ +x); // printing
values of x by using System.out.println only } } }

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
Examine the following program and thoroughly explain what Is wrong with the code. The program should print the values 1 through 10. Rewrite the code inside the main method so it works correctly while maintaining the basic structure of the provided code (l.e., don\'t rewrite the code as a for loop or ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4