Can someone tell me how to fix this please
im practicing how to do the do while loop in java and i cannot figure out how to lmake it start with zero instead of one so that the output would be o is o doubled and then quadrupled instedead of it saying number 1 and so forth.
Can someone please tell me how to do that?
here is the code i have written so far.
Code Java:
// NewestDoubleQuadruple.java - This program prints the numbers 0
through 10 along
// with their values doubled and quadrupled.
// Input: None.
// Output: Prints the numbers 0 through 10 along with their
doubles and quadruples.
public class NewestDoubleQuadruple
{
public static void main(String args[])
{
String head1 = "Number: ";
String head2 = "Doubled: ";
String head3 = "Quadrupled: ";
int numberCounter; // Number 0 through 10.
int doubled; // Stores the double of a
number.
int quadrupled; // Stores the quadruple of
a number.
final int NUM_LOOPS = 10; // Constant used to
control loop.
// This is the work done in the housekeeping()
method
System.out.println("Doubles and Quadruples" +
"\n");
// This is the work done in the detailLoop()
method
numberCounter = 0;
// Write your do while loop here
do
{
numberCounter++;
doubled=numberCounter*2;
quadrupled=numberCounter*4;
System.out.println(head1 + numberCounter);
System.out.println(head2 + doubled);
System.out.println(head3 + quadrupled);
}
while(numberCounter<NUM_LOOPS);
// This is the work done in the EndOfJob() method
System.exit(0);
} // End of main() method.
} // End of NewestDoubleQuadruple class.
Re: Can someone tell me how to fix this please
Put the line:
to the end of do's body section.
java memory
Re: Can someone tell me how to fix this please
Quote:
Originally Posted by
namhm
Put the line:
to the end of do's body section.
Instead of simply telling him what to do, why don't you explain why that solves the problem? I appreciate you're trying to help, but simply posting code isn't helpful by itself. It's best to explain the "why" of the situation, not just the "what".
Re: Can someone tell me how to fix this please
Quote:
Originally Posted by
KevinWorkman
Instead of simply telling him what to do, why don't you explain why that solves the problem? I appreciate you're trying to help, but simply posting code isn't helpful by itself. It's best to explain the "why" of the situation, not just the "what".
Okay, guy, I was thinking that it is pretty simple for him to understand.
I explain it here: because the value of the variable numberCounter is increased by one before the System.out.println() gets called, so if you want to make it starts with zero, put the line numberCounter++ at the end of the do-while's body.
java memory
Re: Can someone tell me how to fix this please
Quote:
Originally Posted by
namhm
Okay, guy, I was thinking that it is pretty simple for him to understand.
It might be simple to understand, but it's more helpful to supply the "why" of the situation than it is to supply "just do this". Especially for newbies, it can be pretty hard to connect the code to what the program does, and oftentimes just a few sentences explaining what's going on can go a lot further than a line of code.
Re: Can someone tell me how to fix this please
Quote:
Originally Posted by
KevinWorkman
It might be simple to understand, but it's more helpful to supply the "why" of the situation than it is to supply "just do this". Especially for newbies, it can be pretty hard to connect the code to what the program does, and oftentimes just a few sentences explaining what's going on can go a lot further than a line of code.
Thanks Kevin, I will update the way of my answer in subsequent posts.