# Working with \$

• April 11th, 2012, 12:07 PM
whome
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.

• April 11th, 2012, 12:26 PM
JoeBrown
Re: Working with \$
Why not just put "\$" + input

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

If 100is entered then the output would be \$ 100
• April 11th, 2012, 12:30 PM
whome
Re: Working with \$
I don't need it to be \$100....I would need 100 dollar signs..... as in the output would be. \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$ \$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$

lol
• April 11th, 2012, 12:33 PM
Norm
Re: Working with \$
Use a for loop with a print() statement
• April 11th, 2012, 01:02 PM
whome
Re: Working with \$
Sorry....i'm pretty new to programming......example?
• April 11th, 2012, 01:11 PM
Norm
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)
• April 11th, 2012, 02:35 PM
whome
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....
• April 11th, 2012, 02:37 PM
Norm
Re: Working with \$
Quote:

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.
• April 11th, 2012, 02:52 PM
whome
Re: Working with \$
Lab7_Ex1.java:16: error: cannot find symbol
for (number = 1; number <= 5; \$++)
^
symbol: variable \$
location: class Lab7_Ex1
1 error
• April 11th, 2012, 02:56 PM
Norm
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
• April 11th, 2012, 03:03 PM
whome
Re: Working with \$
Just java right now....told you I was new :D
• April 11th, 2012, 03:05 PM
Norm
Re: Working with \$
Then it will be better to copy from a working example instead of trying to make it up.
• April 11th, 2012, 03:11 PM
whome
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
• April 11th, 2012, 03:14 PM
Norm
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.
• April 11th, 2012, 03:19 PM
whome
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.");
• April 11th, 2012, 03:29 PM
Norm
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.
• April 11th, 2012, 03:36 PM
KucerakJM
Re: Working with \$
Here is a quickie example for ya whome:
Code java:

```// 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.
• April 11th, 2012, 03:39 PM
whome
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.");
• April 11th, 2012, 03:42 PM
Norm
Re: Working with \$
Take EVERYTHING out of the loop except for the print statement. Did you miss reading post #16?
• April 11th, 2012, 03:51 PM
whome
Re: Working with \$
that just makes it constantly run.....it needs a value to know what to do
• April 11th, 2012, 04:00 PM
Norm
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.