Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 21 of 21

Thread: how to count and print asterisk.

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question how to count and print asterisk.

     int ct=0;
        BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
        do {
     
     
        System.out.println("Enter Grade:");
        int grade=0;
        grade = Integer.parseInt(input.readLine());
     
        ct++;
     
    // start
     
        if(grade==0 || grade==1 || grade==2 || grade==3 || grade==4 || grade==5 || grade==6 || grade==7 || grade==8 || grade==9 || grade==10)
        { // missing statement and agruments} 
        else if(grade==11 || grade==12 || grade==13 || grade==14 || grade==15 || grade==16 || grade==17 || grade==18 || grade==19 || grade==20)
        {}
        else if(grade==21 || grade==22 || grade==23 || grade==24 || grade==25 || grade==26 || grade==27 || grade==28 || grade==29 || grade==30)
        {}
        else if(grade==31 || grade==32 || grade==33 || grade==34 || grade==35 || grade==36 || grade==37 || grade==38 || grade==39 || grade==40)
        {}
        else if(grade==41 || grade==42 || grade==43 || grade==44 || grade==45 || grade==46 || grade==47 || grade==48 || grade==49 || grade==50)
        {}
        else if(grade==51 || grade==52 || grade==53 || grade==54 || grade==55 || grade==56 || grade==57 || grade==58 || grade==59 || grade==60)
        {}
        else if(grade==61 || grade==62 || grade==63 || grade==64 || grade==65 || grade==66 || grade==67 || grade==68 || grade==69 || grade==70)
        {}
        else if(grade==71 || grade==72 || grade==73 || grade==74 || grade==75 || grade==76 || grade==77 || grade==78 || grade==79 || grade==80)
        {}
        else if(grade==81 || grade==82 || grade==83 || grade==84 || grade==85 || grade==86 || grade==87 || grade==88 || grade==89 || grade==90)
        {}
        else if(grade==91 || grade==92 || grade==93 || grade==94 || grade==95 || grade==96 || grade==97 || grade==98 || grade==99 || grade==100)
        {}
        else { System.out.println("Error only 0-100!Going back to Menu"); menus(); } 
     
    //end of else if conditions
     
     
            }  while(ct<=9);// do bracket;
     
     
       System.out.println("00-10"+asterisk+"");
       System.out.println("11-20"+asterisk2+"");
       System.out.println("21-30"+asterisk3+"");
       System.out.println("41-50"+asterisk4+""); // display grades and count using asterisk(*)
       System.out.println("61-70"+asterisk5+"");
       System.out.println("71-80"+asterisk6+"");
       System.out.println("81-90"+asterisk7+"");
       System.out.println("91-100"+asterisk8+"");
    }


    My problem is that i don't know how to count it after the input of grades and print asterisk on each condition.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: how to count and print asterisk.

    I'm really not sure what your question is, but you might want to look into for loops?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    how to count it
    What is the "it" that is being counted?
    Does the program's output show the problem? If so, copy the output here and add some comments to it that shows what is wrong with the output and show what the output should be.

    Are you trying to count the grade values in specific ranges?
    You can detect ranges by using the >= and <= operators instead of using the == operator for all the values.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    run:
    Enter Grade:
    1
    Enter Grade:
    2
    Enter Grade:
    3
    Enter Grade:
    4
    Enter Grade:
    5
    Enter Grade:
    6
    Enter Grade:
    7
    Enter Grade:
    8
    Enter Grade:
    9
    Enter Grade:
    10
    00-10 10 -> // the 10 here must be a 10 asterisk symbol.
    11-20
    21-30
    41-50
    61-70
    71-80
    81-90
    91-100
    BUILD SUCCESSFUL (total time: 7 seconds)


    i know how to count it. i just don't know how to convert it to an asterisk
    Last edited by xyldon27; February 7th, 2013 at 10:40 AM. Reason: wrong grammar

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    how to convert it to an asterisk
    please explain. If the count is 3 how would that be converted?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    run:
    Enter Grade:
    79
    Enter Grade:
    89
    Enter Grade:
    86
    Enter Grade:
    45
    Enter Grade:
    67
    Enter Grade:
    81
    Enter Grade:
    55
    Enter Grade:
    99
    Enter Grade:
    100
    Enter Grade:
    43

    00-10 0
    11-20 0
    21-30 0
    31-40 0
    41-50 2 // 2 must be **
    51-60 1 // 1 must be *
    61-70 1 // 1 must be *
    71-80 1 // 1 must be *
    81-90 3 // 3 must be ***
    91-100 2 // 2 must be **
    BUILD SUCCESSFUL (total time: 23 seconds)

    --- Update ---

    Quote Originally Posted by Norm View Post
    please explain. If the count is 3 how would that be converted?
    3 must be = ***

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    If the *s are being printed, look at using the print() method inside a loop to print *s all on one line.
    Then use the println() method to move to the next line.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    Quote Originally Posted by Norm View Post
    If the *s are being printed, look at using the print() method inside a loop to print *s all on one line.
    Then use the println() method to move to the next line.
    how can i convert an integer of 3 to a three asterisk(***) ?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    You can't. Use the int value to control the loop with the print("*") inside it.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    inside the do while loop or i will create a new one?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    You would need a special loop at the place where you want to print the *s.
    You'd probably want to write a method to do it that you would pass the number of *s to be printed as its arg.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    run:
    How many Students? :
    40
    Enter Grade :
    11
    Enter Grade :
    11
    Enter Grade :
    11
    Enter Grade :
    11
    Enter Grade :
    11
    Enter Grade :
    1
    Enter Grade :
    1
    Enter Grade :
    1
    Enter Grade :
    Enter Grade :
    1
    1
    Enter Grade :
    22
    Enter Grade :
    22
    Enter Grade :
    22
    Enter Grade :
    22
    Enter Grade :
    22
    Enter Grade :
    33
    Enter Grade :
    33
    Enter Grade :
    33
    Enter Grade :
    3
    Enter Grade :
    33
    Enter Grade :
    44
    Enter Grade :
    44
    Enter Grade :
    44
    Enter Grade :
    44
    Enter Grade :
    44
    Enter Grade :
    Enter Grade :
    55
    55
    Enter Grade :
    66
    Enter Grade :
    66
    Enter Grade :
    77
    Enter Grade :
    88
    Enter Grade :
    99
    Enter Grade :
    100
    Enter Grade :
    87
    Enter Grade :
    76
    Enter Grade :
    Enter Grade :
    54
    43
    Enter Grade :
    77
    Enter Grade :
    88
    Enter Grade :
    99











    00-10 6 ******
    11-20 5 *****
    21-30 5 *****
    31-40 4 ****
    41-50 6 ******
    51-60 3 ***
    61-70 2 **
    71-80 3 ***
    81-90 3 ***
    91-100 3 ***










    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    00-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100
    BUILD SUCCESSFUL (total time: 28 seconds)


    im almost finish. how can i align my output. This
    to

    *
    *
    * *
    * * * * * * * * * *
    00-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100 ");

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    The printf() method has formatting capabilities that would help you have spaces to make the columns align.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    Thanks. I got confuse with the printf

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    If you have a question about some code, post the code and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

    *
    *
    *
    *
    *
    *
    *
    *
    *
    *
    00-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100
    BUILD SUCCESSFUL (total time: 10 seconds)


    i can't align them..

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    Please explain what you mean by "align".
    what do you want the output to look like?
    Put the output in code tags to preserve its formatting.
    1
       2
           4
            8
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

      for(int av=ct1;av>=1;av--){
    System.out.println("  *  ");
      } 
     
     
     
                for(int bv=ct2;bv>=1;bv--){
    System.out.println("  \t*  ");}
                  for(int cv=ct3;cv>=1;cv--){
    System.out.println("\t\t*  ");}  
                   for(int dv=ct4;dv>=1;dv--){
    System.out.println("\t\t      *  ");}
                      for(int ev=ct5;ev>=1;ev--){
    System.out.println("\t\t\t    *  ");}
                        for(int fv=ct6;fv>=1;fv--){
    System.out.println("\t\t\t\t  *  ");}
                          for(int gv=ct7;gv>=1;gv--){
    System.out.println("\t\t\t\t\t*  ");}
                            for(int hv=ct8;hv>=1;hv--){
    System.out.println("\t\t\t\t\t      *  ");}
                              for(int iv=ct9;iv>=1;iv--){
    System.out.println("\t\t\t\t\t\t    *  ");}
                                for(int jv=ct10;jv>=1;jv--){
    System.out.println("\t\t\t\t\t\t\t  *  ");}
     
     
      System.out.println("00-10  11-20  21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100 ");
     
     
    //i like the alignment to be like this 
     
       *
       *                                                   
       *      *                                         
       *      *          
    00-10  11-20  21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100

    output must be like a graph of asterisk
    Last edited by xyldon27; February 7th, 2013 at 02:22 PM. Reason: aligning properly

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    What does the output from the program look like? How is it different from what you want?

    The posted code is poorly formatted. The ending }s should not be HIDDEN at the end of a statement.
    All the for statements that are at the same logic level should start in the same column.
    The println() statements should be indented.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    Jun 2009
    Posts
    21
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to count and print asterisk.

        *  
      *  
      *  
      *  
      *  
      	*  
      	*  
      	*  
      	*  
      	*  
      	*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		*  
    		      *  
    		      *  
    			    *  
    			    *  
    			    *  
    			    *  
    				  *  
    				  *  
    				  *  
    				  *  
    				  *  
    					*  
    					*  
    					*  
    					*  
    					*  
    					*  
    					      *  
    					      *  
    					      *  
    					      *  
    					      *  
    						    *  
    						    *  
    						    *  
    						    *  
    							  *  
    							  *  
    00-10  11-20  21-30 31-40 41-50 51-60 61-70 71-80 81-90 91-100

    mine look like this. the asterisk must start from bottom and align with respective numbers

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to count and print asterisk.

    Your logic will have to print the rows starting at the top, build each row column by column, inserting an * when a column should have an *. There would be as many rows as the tallest column to be built.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Asterisk Graph
    By ThatBeast in forum Java Theory & Questions
    Replies: 3
    Last Post: January 4th, 2013, 09:22 PM
  2. Column count doesn't match value count at row 1
    By Tyluur in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 30th, 2012, 01:31 AM
  3. Replies: 1
    Last Post: December 3rd, 2012, 02:35 PM
  4. Count and Print 1 to 10 in Real Time - Help :S
    By djl1990 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 29th, 2012, 05:26 PM
  5. help with loop to print an equliateral asterisk triangle
    By everyone0 in forum Loops & Control Statements
    Replies: 13
    Last Post: October 11th, 2012, 12:37 PM