Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

import java.util.*;
 public class Main.java() {
    public static String customerDetails[][]=new String[5][3];
    Main()
	{
	customerDetails[0][0]="1001";
	customerDetails[0][1]="Raj";
	customerDetails[0][2]="Chennai";
	
	customerDetails[1][0]="1008";
	customerDetails[1][1]="Akshay";
	customerDetails[1][2]="Pune";
	
	customerDetails[2][0]="1002";
	customerDetails[2][1]="Simrath";
	customerDetails[2][2]="Amristar";
     customerDetails[3][0]="1204";
	customerDetails[3][1]="Gaurav";
	customerDetails[3][2]="Delhi";
	
	customerDetails[4][0]="1005";
	customerDetails[4][1]="Ganesh";
	customerDetails[4][2]="Chennai";
	
	}
  
	public static void main(String args[] ) throws Exception 
	{
		Main m = new Main();
		String arr[] = new String[5];
		for(int i=0;i<5;i++) 
		{
		    arr[i] = m.customerDetails[i][1];
		}
		Arrays.sort(arr);
		for(int i=0;i<5;i++) 
		{
		    for(int j=0;j<5;j++) 
		    {
		        if(arr[i].equalsIgnoreCase(m.customerDetails[j][1]))
		        {
		            System.out.println(m.customerDetails[j][0]);
		            System.out.println(m.customerDetails[j][1]);
		            System.out.println(m.customerDetails[j][2]);
  }
		    }
		}
	}
}


What I have tried:

iam getting error in line 7 can you please slove my error
Posted
Updated 12-Aug-22 18:25pm
v2

1 solution

Look at line 7:
Java
public class Main.java() {


Class names cannot contain decimal points: "Main.java" is not a valid class name. The file extension is not needed as part of a class name.

Classes are not methods: the "()" after a name indicates this is a method definition that takes no parameters, or a call to a method.

So try this:
Java
public class Main {
And it should compile.

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900