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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Simple JAVA code help

    I am new to this, and have wrote the code, but keep getting the same error and completely clueless on what to do next. Any help would be greatly appreciated.


    import java.util.*;
    public class A1RE5161843 {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter length of rectangle :");
    double length = input.nextDouble();

    System.out.print("Enter width of rectangle :");
    double width = input.nextDouble();

    System.out.println("Area: "+(length * width));
    System.out.println("Perimeter: "+((2*length)+(2*width)));
    }

    }




    Main.java:12: class A1RE5161843 is public, should be declared in a file named A1RE5161843.java
    public class A1RE5161843 {
    ^
    1 error

  • #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
    The code compiles and runs fine. It looks like you don't have the correct file name in use, or that you're not running the javac properly if manually doing it from the command line.
    Did you use an IDE for this, or did you just create a text file? Check the directory for this, and see what the extension is (it has to be .java).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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