public class MyClass { public static void main(String[] args) { for (int x = 1; x <= 10; x++) { System.out.print("-x" + x); } } }
If this simple program is compiled and run, the following is written to the standard output. -x1-x2-x3-x4-x5-x6-x7-x8-x9-x10
Add only one statement to the line 8. As a result of that the program writes “-x1-x7” to the standard output.
The statemnet we have to add is x=x+5;
public class MyClass {
public static void main(String[] args)
{
for (int x = 1; x <= 10; x++)
{
System.out.print("-x" + x);
x=x+5;
}
}
}
below is the screen shot of the code for your reference purpose:
output:
Get Answers For Free
Most questions answered within 1 hours.