On 07/11/09 14:56, Colm Buckley wrote:
> On Sat, Nov 7, 2009 at 9:32 AM, Frank Murphy (Frankly3D)
> <frankly3d at gmail.com <mailto:frankly3d at gmail.com>> wrote:
>> System.out.print\n("Number Squared Cubed"); // this line
> was the hint we were given
>>> This is where you're going wrong. There are quite a few things wrong
> here - firstly you have a typo; I expect that the 'print\n' should be
> "println", ie: output the string followed by a newline. This really
> should be obvious; if you don't understand why the \ was a problem, I
> think you might be trying to run before walking.
Tried it, instead of printint 1 to 10, 1to 10 Squared\cubed.
Just prints the string 10 times.
>> Secondly, what you're outputting is the string "Number Squared
> Cubed", which presumably isn't what you want. You can either use the
> Formatter class to convert the numbers into a formatted string and then
> output that string, or you can use the printf method to do it in one
> operation.
As per given hint. Which as you suggest may be incorrect?
>> Finally, you need the "squared" and "cubed" calculations to be inside
> the loop, not above it; as it stands the code will calculate "squared"
> and "cubed" once, of "number" (which is zero), and then loop around ten
> times printing the result (0, 0, 0).
>> Something like the below is probably closer to what you want:
>> public class Table {
> public static int Squared(int N) {
> return N * N;
> }
> public static int Cubed(int N) {
> return N * N * N;
> }
> public static void main(String[] a) {
> int Number;
> for (Number = 1; Number <= 10; Number++) {
> System.out.printf("%5d %5d %5d\n",
> Number,
> Squared(Number),
> Cubed(Number));
> }
> }
> }
>> This has the feeling of homework; in which case I think you might need
> to look a bit more closely at some examples. Just getting the answer is
> not the important part of homework; it's understanding the why and how.
>> Colm
>>It's the how and why, am trying to figure out.
Have checked as many for\while as I could find.
But am blind to the "logic" at times.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!