Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: new program

  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    81
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,740
    Thanks
    41
    Thanked 191 Times in 190 Posts
    change this
    // 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

  • #5
    New Coder
    Join Date
    Jun 2009
    Posts
    81
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •