Results 1 to 7 of 7
Thread: number equals astrisks ????
- 10-06-2008, 03:09 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 19
- Rep Power
- 0
number equals astrisks ????
hi,
i need help in my program that asks a user to input an integer then it is supposed to interpret this number into astrisks .i.e, when a user input 7 the program should print (*******) . i should use loop statement .
below is my program :
Java Code:import java.util.Scanner; public class AstrisksLine { public static void main (String[] args) { int x=1; int count=0; Scanner keyboard= new Scanner(System.in); System.out.print("Please enter an integer or (exit) to stop:"); x=keyboard.nextInt(); while (x >=1); x++; { System.out.print("Please enter an integer or (Exit) to stop:"); x=keyboard.nextInt(); for ( count = 0; count>=x; count++) { System.out.print("*" + count ); x=keyboard.nextInt(); } } } }
- 10-06-2008, 07:41 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Okay, and what, exactly, is your problem?
What compiler/error messages are you getting, and/or what is happening that should not be and is not happening that should be?
- 10-06-2008, 07:53 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 19
- Rep Power
- 0
number equals astrisks ????
hi,
I try to make some change to my program ,but the same . the problem is that the program asks the user for an integer and when the user enter it ,the program stops and does not compile to interepret the number into astrisks .for example 4 must display **** .
here is my code :
Java Code:import java.util.Scanner; public class AstrisksLine { public static void main (String[] args) { int x=1; int count=1; Scanner keyboard= new Scanner(System.in); System.out.print("Please enter an integer or (exit) to stop:"); x=keyboard.nextInt(); while (x >=1); x++; { System.out.print("Please enter an integer or (Exit) to stop:"); x=keyboard.nextInt(); for ( count = 1; count>=x; count++) { System.out.print("*" + count ); x=keyboard.nextInt(); } } } }
- 10-06-2008, 08:05 AM #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
what is your problem? Post an output/error message.
I die a little on the inside...
Every time I get shot.
- 10-06-2008, 08:08 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 19
- Rep Power
- 0
hi,
there is no output or error message . just the program stops and does not compile anything after the integer entry of the user .
- 10-06-2008, 08:29 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Well, since the semi-colon ( ; ) ends the statement this
is an endless loop unless x is zero or less.Java Code:while (x >=1);
- 10-06-2008, 09:47 AM #7
if you want to ask a user for an input Integer or something else,and you have some condition to input the specific stuff,use do-while loop,the nexts step in for loop,you want to print the numebr of asterics which equals to an input number,so you should count your asterics in "for loop" from 1 to the input number,but in your for loop statement i see that you won't enter the loop at all,or you will print only one sterics if you input Integer 1,so it should be:
Java Code:for ( count = 0; count<x; count++)
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
Creating a new equals() method help
By Dave0703 in forum New To JavaReplies: 2Last Post: 09-21-2008, 05:32 PM -
Object class's equals() method behavior????
By skyineyes in forum New To JavaReplies: 4Last Post: 07-19-2008, 11:58 PM -
Why Equals method should be over ridden in Hashcode?
By skyineyes in forum New To JavaReplies: 1Last Post: 05-26-2008, 04:13 PM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks