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!
Printable View
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!
Why not just put "$" + input
System.out.println("$ " + input);
If 100is entered then the output would be $ 100
I don't need it to be $100....I would need 100 dollar signs..... as in the output would be. $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
lol
Use a for loop with a print() statement
Sorry....i'm pretty new to programming......example?
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)
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....
Did you try it?Quote:
I don't think that'd work
Write the code, execute it and post the output to show what it does.
Lab7_Ex1.java:16: error: cannot find symbol
for (number = 1; number <= 5; $++)
^
symbol: variable $
location: class Lab7_Ex1
1 error
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
Just java right now....told you I was new :D
Then it will be better to copy from a working example instead of trying to make it up.
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
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.
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.");
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.
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.
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.");
Take EVERYTHING out of the loop except for the print statement. Did you miss reading post #16?
that just makes it constantly run.....it needs a value to know what to do
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.