468,167 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,167 developers. It's quick & easy.

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

1
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.length();
System.out.println("My fullname is " + meFullname + ".");
System.out.println("My name has" + " " + letters + " " + "letters.");
}
}

Thank you!
Attached Images
File Type: jpg Dunno if there has a problem Strings.jpg (100.6 KB, 92 views)
File Type: jpg NoRightSolution.jpg (70.7 KB, 80 views)
Dec 29 '18 #1
2 3125
Luuk
1,043 Expert 1GB
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. 😉
Jan 1 '19 #2
Ishan Shah
47 32bit
The name of the public class must same as the name of the .java file in which it is placed like
Expand|Select|Wrap|Line Numbers
  1. 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
    Expand|Select|Wrap|Line Numbers
    1. public class Demo { 
    to
    Expand|Select|Wrap|Line Numbers
    1.  public class Main {
Feb 25 '21 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Virtual_X | last post: by
2 posts views Thread by =?Utf-8?B?bWVtb2lyaQ==?= | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.