how to count and print asterisk.
Code :
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.
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?
Re: how to count and print asterisk.
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.
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(*)
Re: how to count and print asterisk.
Quote:
how to convert it to an asterisk
please explain. If the count is 3 how would that be converted?
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
please explain. If the count is 3 how would that be converted?
3 must be = ***
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.
Re: how to count and print asterisk.
Quote:
Originally Posted by
Norm
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(***) ?
Re: how to count and print asterisk.
You can't. Use the int value to control the loop with the print("*") inside it.
Re: how to count and print asterisk.
inside the do while loop or i will create a new one?
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.
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 ");
Re: how to count and print asterisk.
The printf() method has formatting capabilities that would help you have spaces to make the columns align.
Re: how to count and print asterisk.
Thanks. I got confuse with the printf
Re: how to count and print asterisk.
If you have a question about some code, post the code and your questions.
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.. :(
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.
Re: how to count and print asterisk.
Code :
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
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.
Re: how to count and print asterisk.
Code :
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
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
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.