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!
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.
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
If you don't understand my answer, don't ignore it, ask a question.
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)
If you don't understand my answer, don't ignore it, ask a question.
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?I don't think that'd work
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.
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
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.
Just java right now....told you I was new![]()
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.
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.
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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.
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?
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.