hi guys am quite new in java programming and i v got a small problem to
sort out and the problem is as followed:
Using loops print your name on the screen X times. Where X is the
number you will input from the user, then clear the screen and display
the result X many times.
so i here is are my workings but could not sort it out.Can anyone tell
me what mistake have i done in that and how to solve it,please?Thx
public class loops{
public static void main(String Arg []){
String x="_";
String y="Geeresh";
x=JOptionPane.showInputDialog("how many times to print my name?");
int a=Integer.parseInt(x);
int b=Integer.parseInt(y);
for(a=0;a<b;a++){
String p=b+"\n";
System.out.println(p);
}
}
}
TechBookReport - 23 Mar 2006 17:14 GMT
> hi guys am quite new in java programming and i v got a small problem to
> sort out and the problem is as followed:
[quoted text clipped - 18 lines]
> }
> }
Look at the value of the y variable...What are you expecting it to
contain and what does it really contain?

Signature
TechBookReport Java http://www.techbookreport.com/JavaIndex.hml
Roedy Green - 23 Mar 2006 17:52 GMT
On 23 Mar 2006 08:00:51 -0800, "help needed here"
<geeresh@googlemail.com> wrote, quoted or indirectly quoted someone
who said :
> String x="_";
> String y="Geeresh";
> x=JOptionPane.showInputDialog("how many times to print my name?");
>int a=Integer.parseInt(x);
>int b=Integer.parseInt(y);
variable names are not arbitrary. y is alctually "lastName". b is
Lord know what -- the numerological Kabalarian rendering of yoru name?
x is "timesToPrint". Use proper variables names and bugs will leap
out at you.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Monique Y. Mudama - 23 Mar 2006 18:37 GMT
> hi guys am quite new in java programming and i v got a small problem to
> sort out and the problem is as followed:
[quoted text clipped - 18 lines]
> }
> }
What result did you expect when you tried to get the integer value of
"Geeresh"?

Signature
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Tom Leylan - 24 Mar 2006 03:25 GMT
This is another one of those classic problems. The code isn't wrong as much
as as the routine is incorrectly named. Rename it to
NoLoopsAndNoClearScreen() and it works as advertised.
You know the real problem the Internet has brought us? Many of us had to
write this on a 1MHz CPU with 16K of RAM and had nobody to ask. Then hours
later you called your friend or your mom to come see what you made the
computer do. You learned fast or you gave up before NameLooper got out of
alpha test.
>> hi guys am quite new in java programming and i v got a small problem to
>> sort out and the problem is as followed:
[quoted text clipped - 21 lines]
> What result did you expect when you tried to get the integer value of
> "Geeresh"?
help needed here - 26 Mar 2006 21:56 GMT
the result that i am expecting is that the while the user input the
number of times h/she wants to print his/her name ,the name should be
displayed that number of times...my name is geeresh and suppose i want
to print my name (3) times it should appear like this :
geeresh
geeresh
geeresh
help me if u know how to tackle it please
Oliver Wong - 27 Mar 2006 15:56 GMT
> the result that i am expecting is that the while the user input the
> number of times h/she wants to print his/her name ,the name should be
[quoted text clipped - 4 lines]
> geeresh
> help me if u know how to tackle it please
I'm gonna repost the code Monique was highlighting, and trim it down
further, and then perhaps you can see why it's not doing what you expect.
<code>
String y="Geeresh";
int b=Integer.parseInt(y);
</code>
And as an extra hint, here's a part of Monique's post again:
<quote>
What result did you expect when you tried to get the integer value of
"Geeresh"?
</quote>
- Oliver
Oliver Wong - 23 Mar 2006 18:59 GMT
> hi guys am quite new in java programming and i v got a small problem to
> sort out and the problem is as followed:
> Using loops print your name on the screen X times. Where X is the
> number you will input from the user, then clear the screen and display
> the result X many times.
Are you sure the problem statement says "Clear the screen"? It seems
like a strange request to be made, given the (lack of) complexity in the
rest of the problem.
- Oliver
Roedy Green - 23 Mar 2006 22:01 GMT
On 23 Mar 2006 08:00:51 -0800, "help needed here"
<geeresh@googlemail.com> wrote, quoted or indirectly quoted someone
who said :
> then clear the screen
see http://mindprod.com/jgloss/console.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.