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: Working with $

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Working with $

    I am writing a program and trying to multiply with $ if thats even possible.

    I am coding a program where the user enters a number, and the output is $$$ of the number entered. So if one is entered, then one $ is output, and so on.


    Thanks in advance!


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    Why not just put "$" + input

    System.out.println("$ " + input);

    If 100is entered then the output would be $ 100

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    I don't need it to be $100....I would need 100 dollar signs..... as in the output would be. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

    lol

  4. #4
    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: Working with $

    Use a for loop with a print() statement
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    Sorry....i'm pretty new to programming......example?

  6. #6
    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: Working with $

    Can you write a for loop? write one that loops 100 times.
    Inside the loop use the print() statement to print a $

    Here's a tutorial on for loops:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    I don't think that'd work.....maybe i'm not explaining it correctly..... If the user enters 7 as the input, the output would be $$$$$$$. If the user enters 3 as the input, the output would be $$$. and so on....

  8. #8
    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: Working with $

    I don't think that'd work
    Did you try it?
    Write the code, execute it and post the output to show what it does.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    Lab7_Ex1.java:16: error: cannot find symbol
    for (number = 1; number <= 5; $++)
    ^
    symbol: variable $
    location: class Lab7_Ex1
    1 error

  10. #10
    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: Working with $

    Take another look at the tutorial I posted the link to. It shows how to write a for statement to control a loop.
    It has examples that you could copy and paste here as a starting point.
    NOTE: $ is a valid variable name
    Last edited by Norm; April 11th, 2012 at 02:30 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    Just java right now....told you I was new

  12. #12
    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: Working with $

    Then it will be better to copy from a working example instead of trying to make it up.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    thats what I am doing.....it doesn't like the $ sign

    Lab7_Ex1.java:16: error: cannot find symbol
    for (number = 1; number>= 5; $++)
    ^
    symbol: variable $
    location: class Lab7_Ex1
    Lab7_Ex1.java:20: error: cannot find symbol

  14. #14
    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: Working with $

    Why are you coding a $ in the for statement?
    Where do you define the variable named: $

    You must define variables before you can use them.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    won't let me define it..... this is what I have so far, but its only giving me one dollar sign ($) no matter what number I enter

    for (number = 1; number <= 5
    {
    System.out.print("Enter the next number: ");
    number = input.nextInt();
    System.out.println("$");

    }
    System.out.print("That is an invalid number.");

  16. #16
    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: Working with $

    Change the loop to ONLY print out the $. Nothing else inside of the loop.
    For a simple test do NOT ask for a number, just assign number a value like 7 and execute the loop with that.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Working with $

    Here is a quickie example for ya whome:
    // The variable i is declared and initialized in the loop, which doesn't have to be the case.
    for (int i = 0; i < 100; i++) {  // the variable i is what we will increment each iteration while it is less than 100; at which point the loop ends.
      System.out.println(i+1);  // This will print the current value of i + 1 so that it will print the numbers 1-100
    }
     
    //  So, the things you need for the loop are as follows (in your case at least)
    // 1) A variable that will be incremented each iteration
    // 2) A starting point, in the example it was 0
    // 3) An end point, in the example it was < 100 (which would really be 99)
    // 4) Increment the variable
    // 5) Do something each iteration; System.out.println(i+1) in the example

    The basic format would be:
    for([incrementVariable] = [startnumber]; [incrementVariable] < [end number]; [incrementVariable]++) {
    Do something
    }

    Note: [incrementVariable] < [end number] <------The equality operator '<' is only used as example and can change based on the situation.

  18. #18
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    Getting there Norm.....now it just gives me one dollar sign ($) no matter what number I input
    int number;
    String symbol = "$";


    for (number = 1; number <= 5
    {
    System.out.print("Enter a number: ");
    number = input.nextInt();
    System.out.println(symbol);

    }
    System.out.print("That is an invalid number.");

  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: Working with $

    Take EVERYTHING out of the loop except for the print statement. Did you miss reading post #16?
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working with $

    that just makes it constantly run.....it needs a value to know what to do

  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: Working with $

    So it is able to print out a 100 or 1million $s now?
    Assign it a value for testing. I suggested 7 in post#16.
    Later you can ask the user for the number.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Jar not WORKING FOR ANYONE BUT ME!!!!!!!! HELP
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 12
    Last Post: February 18th, 2012, 07:32 AM
  2. not sure why the 'else is not working
    By reddevilggg in forum Loops & Control Statements
    Replies: 3
    Last Post: September 30th, 2011, 03:54 PM
  3. Why isn't this working?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: January 21st, 2011, 04:08 PM
  4. Cannot seem to get this working
    By OttawaGuy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 28th, 2010, 03:41 PM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM