简体   繁体   中英

How to solve syntax error in eclipse Mars.1

Here is my code :

import java.util.Scanner

class VersatileSnitSoft
       public static void main (String [] args) {
       double amount; 

       System.out.print (*What is the price of CD-ROM? *)
       amount = myScanner.nextDouble ();
       amount = amount + 25.00;

       System.out.print(*We will bill R*);
       System.out.print(amount);
       System.out.printIn(* to your credit card.*)
     }
}
  System.out.print(*What is the price of CD-ROM? *)

字符串应包含在""而不是**并且此语句末尾的分号在哪里。

Your code should be right in this mode.

 import java.util.Scanner;

public class VersatileSnitSoft {
    public static void main (String [] args) { 
        double amount;
        Scanner myScanner = new Scanner(System.in);
        System.out.print ("What is the price of CD-ROM? ");
        amount = myScanner.nextDouble ();
        amount = amount + 25.00;

        System.out.print("We will bill R ");
        System.out.print(amount);
        System.out.println(" to your credit card.");
    }
}

try to read some tuturial like this Learn java

There weren't many things correct here. I suggest you start from the bottom and actually read up on how the syntax looks, how the language works.

That being said, your code now looks

import java.util.Scanner;

class VersatileSnitSoft {

    public static void main (String [] args) {
        double amount;

        Scanner myScanner = new Scanner (System.in);

        System.out.print ("What is the price of CD-ROM? ");
        amount = myScanner.nextDouble ();
        amount += 25.00;

        System.out.print("We will bill R" + amount + " to your credit card.");

        myScanner.close();
    }
}

The changes made are:

  • You never initialized the scanner, you just used it.
  • You made up your own method printIn which doesn't exist, I suggest it was supposed to be println (...)
  • You used * around a string instead of quotation " .
  • You forgot ; at the end of one line.
  • You also have to close the Scanner , which I showed how now.

For the future, read the error messages and try to understand them, at least share them with us. This code now produces zero errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM