# Turning numbers into asterisks.

• 02-24-2009, 08:01 AM
BugginVT
Turning numbers into asterisks.
I've only been working with java for probably two weeks so you'll have to excuse the mess. The program I have here has an array set for a high number, runs down and asks the user to input numbers (assuming numbers are in increments of 100), then divides the numbers by 100 and outputs them. What I'm looking to do is instead of just outputting the numbers, I'd like to have asterisks represent for numbers. For every 100 that the user types in, will output a single *. So say the user inputs 1400, it divides it by 100, from this point, how do I get an output of **************?

Code:

```import java.util.Scanner; public class Astericks3 {         /**         * @param args         */         public static void main(String[] args)         {                 //priming reed                                int exitCheck = 0;  //used to exit loop when 999 is typed                 int salesCount = 1;  //used to help indicate order during final output                 int Count = -1;  //used to cut off the 999 once exited loop                 int[] inputSales = new int[9999];                 Scanner input = new Scanner(System.in); //initial statement                                System.out.println("Please enter first sales figure");                 //main loop                        for (int i = 0; i < inputSales.length; i++ )                     if(exitCheck != 999)         {                                  inputSales[i] = input.nextInt();                         System.out.println("Enter next sales figure, or 999 to exit: ");                                        exitCheck = inputSales[i];                                 ++Count;                 }            //dividing the input by 100                for (int i = 0; i < Count; ++i)         {                 inputSales[i] = inputSales[i]/100;         }         //system output                {                 for ( int i = 0; i < Count; ++i )                 {                     System.out.println("Number " + salesCount +  " sales: "  + inputSales[i]);                         salesCount++;                 }                 System.out.println("Thank you!");         }                             } }```
• 02-24-2009, 08:15 AM
Eranga
You can find the whole number for division. Say the input is 1500, then divide by 100 gives the answer is 14. So in a loop print the asterisk sign. Don't use the new line, that's all.

Code:

```for(int index = 0; index < value; index++) {     System.out.print("*); }```
• 02-24-2009, 08:39 AM
pbrockway2
Quote:

Originally Posted by Eranga
[COLOR="DarkGreen"]Say the input is 1500, then divide by 100 gives the answer is 14.

Shoplifting?
• 02-24-2009, 09:14 AM
Eranga
Oops, it's a simple mistake. Once divide by 100, answer should be 15. ;)
• 02-24-2009, 05:15 PM
BugginVT
So from what I'm understanding, you're saying my output statement should look something like this(below). I'm doing that and it's only printing the amount of numbers I put in. Say I input 900, 1000, 1100, it's only outputting three asterisks.

Code:

```for(int i = 0; index < inputSales[i]; i++)   {     System.out.print("*");   }```

Thanks for the help up to this point!
• 02-24-2009, 08:29 PM
angryboy
Code:

```for(int j=0; j<inputSales.length; j++)   for(int i = 0; index < inputSales[j]/100; i++)     System.out.print("*");```
• 02-25-2009, 06:09 AM
BugginVT
Alright, I think I understood it. I took angryboys code fragment and modified it a bit. I included the final program in case anybody else bumps into this during a search.

Thanks for the help guys!

Code:

```import java.util.Scanner; public class Asterisks3 {         /**         * @param args         */         public static void main(String[] args)         {                 //priming reed                                int exitCheck = 0;  //used to exit loop when 999 is typed                 int salesCount = 1;  //used to help indicate order during final output                 int Count = -1;  //used to cut off the 999 once exited loop                 int[] inputSales = new int[9999];                 Scanner input = new Scanner(System.in); //main loop                        for (int i = 0; i < inputSales.length; i++ )                     if(exitCheck != 999)         {                              System.out.println("Enter sales figure " + salesCount + ", or 999 to exit: ");                         inputSales[i] = input.nextInt();                         exitCheck = inputSales[i];                                        ++Count;                                 ++salesCount;         } //resetting salesCount            salesCount = 1; //System output        for(int r=0; r<Count; r++)     {             System.out.print("Number " + salesCount +  " sales: ");               for(int i = 0; i < inputSales[r]/100; i++)               {                 System.out.print("*");               }               ++salesCount;               System.out.println(" ");     }            System.out.println("Thank you!");                } }```
• 02-25-2009, 07:38 AM
Eranga
While working on read more about arrays. How to use elements and length of it.