Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Creating a Multiplication Program
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slider203




PostPosted: Tue Feb 16, 2010 7:53 pm   Post subject: Creating a Multiplication Program

Hello I am trying to create a multiplication program where the user enters a number then is multiplied by 1 - 12
heres what I have so far

Quote:

//Import the input/output library.
import java.io.*;
class InputPractice1
{
public static void main (String args [])
//Prevents the program from crashing if incorrect input is entered.
throws java.io.IOException
{
// Allows input from the keyboard.
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String name = "number";

System.out.println ("Please enter a number:");
//Waits for user input.
name = br.readLine();

System.out.println (number + "x 1 = " + number * 1); <-----THIS LINE KEEPS GIVING ME PROBLEMS
}
}


I keep getting an error that says
2 errors found:
File: H:\ICS\nEW\InputPractice1.java [line: 33]
Error: cannot find symbol
symbol : variable number
location: class InputPractice1

File: H:\ICS\nEW\InputPractice1.java [line: 33]
Error: cannot find symbol
symbol : variable number
location: class InputPractice1

been trying but I cant get it to work. Please take a look any help is appreciated
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Tue Feb 16, 2010 8:25 pm   Post subject: RE:Creating a Multiplication Program

Where did you declare number? You need to create a variable called number and assign the integer value of name to it.

Also "throws java.io.IOException" will still cause it to crash if there is an exception.

Hope that helps.
DtY




PostPosted: Tue Feb 16, 2010 8:26 pm   Post subject: RE:Creating a Multiplication Program

You are trying to multiply a string by a number. Imagine, what is "hello"*3? It doesn't make sense[1].

To do this, you'll have to either read as an integer (instead of a string), or convert the string to an integer after reading.

[1] Some languages will actually give you "hellohellohello" for this
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: