Results 1 to 7 of 7
  1. #1
    nanna is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Question 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();
     
    
                   
            }      
         } 
                             
       } 
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    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?

  3. #3
    nanna is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default 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();
     
    
                   
            }      
         } 
                             
       } 
    }

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    what is your problem? Post an output/error message.
    I die a little on the inside...
    Every time I get shot.

  5. #5
    nanna is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    hi,
    there is no output or error message . just the program stops and does not compile anything after the integer entry of the user .

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Well, since the semi-colon ( ; ) ends the statement this

    Java Code:
         while (x >=1);
    is an endless loop unless x is zero or less.

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    6

    Default

    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

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Creating a new equals() method help
    By Dave0703 in forum New To Java
    Replies: 2
    Last Post: 09-21-2008, 05:32 PM
  3. Object class's equals() method behavior????
    By skyineyes in forum New To Java
    Replies: 4
    Last Post: 07-19-2008, 11:58 PM
  4. Why Equals method should be over ridden in Hashcode?
    By skyineyes in forum New To Java
    Replies: 1
    Last Post: 05-26-2008, 04:13 PM
  5. Replies: 0
    Last Post: 01-25-2008, 11:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •