Error (3, 8, 13, 44); Java; IntelliJ

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MKKey
    New Member
    • Dec 2018
    • 1

    Error (3, 8, 13, 44); Java; IntelliJ

    Hello, tech people,

    I'm newly appeared at the software stage and I don't know more than I know. So, please bare with me and give me some clear guidelines.

    I'm trying to code some simple solution of one of my first tasks in Java and I can't find my mistake here. The main reason for writing this code is that I want to print my names with the count of its letters.


    package com.company;

    public class Main {

    public static void main(String[] args) {
    // write your code here


    String meFirstName = "Smarty";
    String meLastName = "Trousers";
    String meFullName = meFirstName + " " + meLastName;
    int letters = meFullName.leng th();
    System.out.prin tln("My fullname is " + meFullname + ".");
    System.out.prin tln("My name has" + " " + letters + " " + "letters.") ;
    }
    }

    Thank you!
    Attached Files
    Last edited by MKKey; Dec 29 '18, 07:38 PM. Reason: I need to be more specific.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    It seems yo do not understand the error:
    "Error(3,8) : class Main is public should be declared in a file named Main.java"

    The "(3,8)" says the error in on line #3 somewhere near character 8.
    and for the rest:
    The main class ('Main') seems to be public, which means you have to name the file 'Main.java' (of change line #3 to 'public class xyz', but than you will have to rename the file to xyz.java. 😉

    Comment

    • Ishan Shah
      New Member
      • Jan 2020
      • 47

      #3
      The name of the public class must same as the name of the .java file in which it is placed like
      Code:
      public class Demo{}
      must be placed in the Demo.java file. so either
      • Rename your file from Main.java to Demo.java
      • Rename the class from
        Code:
        public class Demo {
        to
        Code:
         public class Main {

      Comment

      Working...