need help with the code
hi, i'm new to javaq and tryinh to get the output something like this
hello1 hello hello hello
hello hello2 hello hello
hello hello hello3 hello
but cant seem to achieve it. could some one help me? thank you
this is my code so far:
import java.io.*;
public class Testing
{
public static void main(String [] args)
{
//outer loop, loop through number of lines
for( int i=1; i<=3; i++)
{
for (int j=1; j<=4; j++)
{
System.out.print("Hello\t" );
if (i=j)
{
System.out.print("Hello" +i);
}
}
System.out.println();
}
System.out.println("End of Program!");
}
}
1) What specific problem are you having?
2) Next time, use a meaningful subject line. Yours conveys no useful information.
3) When you post code, please use[code] and [/code] tags as described in http://forum.java.sun.com/help.jspa?sec=formatting(Formatting tips) on the message entry page. It makes it much easier to read.
This code is wrong.
System.out.print("Hello\t" );
if (i=j)
{
System.out.print("Hello" +i);
}
You need an if/else statement there and only print Hello without the number if you are not printing Hello with the number
And this won't even compileif (i=j)
change it:
System.out.print("Hello\t" );
if (i=j)
{
System.out.print("Hello" +i);
}
for:
if (i==j) {
System.out.print("Hello" +i);
} else {
System.out.print("Hello " );
}
Wouldn't it have been better to guide the OP toward figuring it out himself, rather than handing him the answer? How do you expect him to learn if you don't let him do his own work?
> Wouldn't it have been better to guide the OP toward
> figuring it out himself, rather than handing him the
> answer? How do you expect him to learn if you don't
> let him do his own work?
He did it for the DUKES!!!!! Don't you know?!?! Those precious, unobtainable, all-important, do-my-homework-for-me DUKES!! Without them, you are NO ONE!!! REAL coders have tons and tons of these arbitrarily awarded, valuless, mebningless, immaterial e-points called duke stars! (How else would one be able to judge a developers ability to write code? Gosh, Jeff ... what were you thinking?
Does that make him a Dukes wh髍e?
> Does that make him a Dukes wh髍e?... something like that. ;-)
> need help with the codeReally? I thought you were having problems with your haemorrhoids!
> He did it for the DUKES!!!!! Don't you know?!?!
> Those precious, unobtainable, all-important,
> do-my-homework-for-me DUKES!! Without them, you are
> NO ONE!!! REAL coders have
> tons and tons of these arbitrarily awarded,
> valuless, mebningless, immaterial e-points called
> duke stars! (How else would one be able to judge a
> developers ability to write code? Gosh, Jeff ...
> what were you thinking?
And gee surprise surprise he didn't even get the dukes. I think a semi truck must have run over the poor OP.
> And gee surprise surprise he didn't even get the
> dukes. I think a semi truck must have run over the
> poor OP.
Naah ... he's just like all the other shitpuff kids that run around here and get others to do their homework assignment for them. Won't show up until the night before his next homework assignment is due...
because he is stupid anyway, what is the use of forum in the first place sharing of ideas ryt?
public class Temp
{
static public void main(String[] args)
{
int i,j,k;
for(i =0; i < 3; i++)
{
for(j = 0; j <= i; j++)
{
System.out.print("Hello ");
}
System.out.print(i+1 + " ");
for(k = 3; k >= j; k--)
{
System.out.print("Hello ");
}
System.out.println();
}
}
}
This code gives the oputput exact that of you have mentioned.