Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-31-2012, 01:58 AM   PM User | #1
royb305
New to the CF scene

 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
royb305 is an unknown quantity at this point
new program

having trouble with this little guy. always saying it needs a ; where the line doesnt end or a ) where the statement isnt even going to be complete. and pointers?
// Allows for user input
import java.util.Scanner;

public class Salary3
{
public static void main (String[] args);
{
// Declare Variables
String name;
double salary;

// Allows to read in from user input
Scanner scan = new Scanner (System.in);

// Prompt user for their name
Syste.out.println ("what is your name?");

// Read in the users name and stores it in the cariable name
name = scan/nextLine();

// Prompt the user for their age
Systems.out.println ("What is your age?");

// Read in the users age and stores it in the variable age
age = scan.netInt ();

// Prompt the user for their wanted salary
System.out.println ("How much money would you like to"
+ " make in a year");

// Read in the users salary and store it in the variable salary
salary = scan.nextDouble ();

// Output the wanted output
System.out.print ("\n" + name + " is " + age);
System.out.println (" years old and would like to make $" +
salary + " a year.);
} // End of main
} // End of Salary
royb305 is offline   Reply With Quote
Old 08-31-2012, 02:07 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I assume this is Java not JavaScript - this is not the section to post a question anyway..

and you should wrap your code in [ CODE ] blocks.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-31-2012, 03:44 AM   PM User | #3
rdspoons
New Coder

 
Join Date: Jun 2009
Posts: 81
Thanks: 0
Thanked 8 Times in 8 Posts
rdspoons is on a distinguished road
A test?
There are seven errors in the posted java code. Can you find them?

match the errors with the line of code:

Errors
1 semi-colon error
1 Declaration error
3 Misspelling errors (3)
1 Keyboard (fat-finger) error
1 Quotation error
rdspoons is offline   Reply With Quote
Old 09-01-2012, 03:47 AM   PM User | #4
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
change this
Quote:
// Prompt the user for their wanted salary
System.out.println ("How much money would you like to"
+ " make in a year");
to this
Code:
// Prompt the user for their wanted salary
System.out.println ("How much money would you like to" + 
" make in a year");
note the movement of the +
Also when posting something like this, where you are getting errors, please post the error message along with the line number. It makes finding the problem easier and faster
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 09-01-2012, 04:41 AM   PM User | #5
rdspoons
New Coder

 
Join Date: Jun 2009
Posts: 81
Thanks: 0
Thanked 8 Times in 8 Posts
rdspoons is on a distinguished road
Code:
//pointers?
// Allows for user input
import java.util.Scanner;

public class Salary3
{
public static void main (String[] args)			// <- 1. corrected semi-colon error on main
{							// Removed the semi-colon
// Declare Variables
String name;
double salary;

// Allows to read in from user input
Scanner scan = new Scanner (System.in);

// Prompt user for their name
System.out.println ("what is your name?");		// <-- 2. Syste was not an Object
							// Replaced Syste with System
// Read in the users name and stores it in the cariable name
name = scan.nextLine();					// <-- 3. could not divide an object by the result of an undefined function call
							// Replaced the division operator with a dot to connect the method to the object
// Prompt the user for their age
System.out.println ("What is your age?");		// <-- 4. Systems was not an object
							// Replaced Systems with System
// Read in the users age and stores it in the variable age
int age = scan.nextInt ();				// <-- 5. age was undclared
							// declared age as int
							// <-- 6. netInt was undefined
							// Replaced netInt with nextInt
// Prompt the user for their wanted salary
System.out.println ("How much money would you like to"
+ " make in a year");

// Read in the users salary and store it in the variable salary
salary = scan.nextDouble ();

// Output the wanted output
System.out.print ("\n" + name + " is " + age);
System.out.println (" years old and would like to make $" +
salary + " a year.");					// <-- 7. the closing double-quote was missing
} // End of main					// Added a closing quote after the period following year.
} // End of Salary
rdspoons is offline   Reply With Quote
Reply

Bookmarks

Tags
new programmer

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:59 AM.


Advertisement
Log in to turn off these ads.