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
  1. #1
    New Coder
    Join Date
    Oct 2011
    Location
    Norfolk, VA
    Posts
    19
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Compile errors but seems correct.

    This is my second post in the past couple of hours about a compiler error, but that was my fault. This time I'm almost 100% i followed the steps correctly in the tutorial and this simple class should compile just fine. I've listed the errors as comments.
    Code:
    import java.util.Scanner;
    
    class VersatileSnitSoft {
    
           public static void main(String args[]) {
                  Scanner myScanner - new Scanner(System.in); 
                 //error ';' expected line 6 ^
                  double amount;
                 //Now here I've set the keyword double to the variablename amount
                 
                System.out.print("What's the price of a CD-ROM? ");
                amount - myScanner.nextDouble();
                //error: not a statement line 10 ^
                amount - amount + 25.00;
                //error: not a statement line 11 ^
    
                System.out.print("We will bill $");
                System.out.print(amount);
                System.out.println(" to your credit card.");
           }
    }
    any help would be greatly appreciated thank you for your time.
    I really just want to know why my amount - myScanner.nextDouble(); isnt' a statement and how do I make it a statement.
    I just started with variables and I by no means am good at this yet.
    Last edited by syronix; 10-21-2011 at 10:18 PM. Reason: add on to the question

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    These should be assignments, not subtractions.
    Java is smart, it won't let you perform operations on something that would provide a distinct result without actually assigning it to something. i++ is fine, but i + 1 would require an assignment.

  • #3
    New Coder
    Join Date
    Oct 2011
    Location
    Norfolk, VA
    Posts
    19
    Thanks
    11
    Thanked 0 Times in 0 Posts

    assignments

    So are you saying I need to assign the variable to something for the class to call?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No I'm saying these need to be assignments for the variables themselves. This class will run standalone since it already has a main method constructed. Unless I misunderstand what you mean?

    This: Scanner myScanner - new Scanner(System.in); should be Scanner myScanner = new Scanner(System.in); , and same for the assignments below with the amount variable.

  • Users who have thanked Fou-Lu for this post:

    syronix (10-21-2011)

  • #5
    New Coder
    Join Date
    Oct 2011
    Location
    Norfolk, VA
    Posts
    19
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Thank you so much that fixed my compile errors, Honestly i thought it should look like this but I didn't want to differ from my instruction just in case i was wrong. Again thanks.


  •  

    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
    •