text: I am prompting the user for a total sales amount in dollars, such as 1200, or 900, etc. For every 100 dollars, I need to display a * character. So if the user enters 500, ***** will show on the screen. So does anyone know how would I do this?
  I am prompting the user for a total sales amount in dollars, such as 1200, or 900, etc. For every 100 dollars, I need to display a * character. So if the user enters 500, ***** will show on the screen. So does anyone know how would I do this?
  Divide the number by 100 and that will tell you how many stars you need. Then use a loop to build a string of that many stars and then output the string.
  This is a simple sample on how to do it. You have to implement the same logic in your algorithm.
  Code:public class Asterisk { public static void main(String[] args) { if(args.length == 0) { System.out.println("No arguments passed"); System.exit(-1); } try { long value = Long.valueOf(args[0]).longValue(); long hundreds = value / 100; System.out.println("number of asterisks ["+hundreds+"]"); for(long i=0; i<hundreds; i++) { System.out.print("*"); } } catch(NumberFormatException ex) { ex.printStackTrace(); System.exit(-1); } } }
  Software and cathedrals are much the same - first we build them, then we pray.
  Lol ckeyrouz, I don't think the op wanted that type of user input to asterisk conversion.
  I think he wanted something at the terminal level.
  Here is some freshly written personal code of mine that does the job.
  Code:import java.util.Scanner; public class BalanceToAsterisk { //variables //establish variable to hold string of asterisks static String asterisk_list = ""; //establish prompt cycle controller static String answer = ""; //establish variable to get user input of value we want to compare to 100 static int balance = 0; //establish variable to accept user input static Scanner scanner = new Scanner ( System.in ); public static void main ( String [ ] args ) { do { //prompt user System.out.println ( ); System.out.print ( "Enter value : " ); balance = scanner.nextInt ( ); if ( is100 ( balance ) ) asterisk_list += "*"; System.out.println ( ); System.out.print ( "Continue ? " ); answer = scanner.next ( ); } while ( answer.equals ( "yes" ) || answer.equals ( "YES" ) || answer.equals ( "y" ) || answer.equals ( "Y" ) ); //when no is toggled, jump out of while loop and print results System.out.println ( "ANSWER : " + asterisk_list ); } //function to check if user input is divisible by 100 - essentially every time 100 is entered static public boolean is100 ( int value ) { boolean flag = false; if ( value % 100 == 0 ) flag = true; else flag = false; return flag; } }
  This code doesn't match what the OP is looking for. If I enter 700 in there, it would give me a result of *. The OP wants 700 = ******* from their description.
  ckeyrouz's is closer, but assumes its part of a argument on the program invocation. The same logic would apply to the scanner.
  PHP Code:
  public static String strRepeat(String sToRepeat, int iTimes)
  {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < iTimes; ++i)
  {
  sb.append(sToRepeat);
  }
  return sb.toString();
  }
  public static void main(String... argv)
  {
  Scanner s = new Scanner(System.in);
  // I won't bother with looping or error checking.
  int iDollars = s.nextInt();
  System.out.println(strRepeat("*", iDollars / 100));
  }
  My bad OP. I guess I read through the code way to quickly.
  In that case, use this code, very short and includes a prompt.
  Code:import java.util.Scanner; public class BalanceToAsterisk { public static void main ( String [ ] args ) { String asterisk_list = ""; //string to accept new asterisks int balance = 0; //user input Scanner scanner = new Scanner ( System.in ); //user input scanner System.out.print ( "Enter balance : " ); balance = scanner.nextInt ( ); for ( int valid_balances = 0; valid_balances < balance / 100; valid_balances ++ ) asterisk_list += "*"; System.out.println ( "Asterisk list : " + asterisk_list ); } }
  oh that seems complicated