I’m very new to Java. Here is my code:
public class funk {
int largest(int a,int b,int c)
{
if(a>b)
{
if(a>c)
{
return a;
}
else if(b>c)
{
return b;
}
else
{
return c;
}
}
}
public class firstprog {
public static void main(String args[]) {
int a=7;
int b=8;
int c=9;
funk punk=new funk();
System.out.println(punk.largest(a,b,c));
}
}
The error that Eclipse gives me is The public type funk must be defined in its own file.
Why is this so?
Yes the problem is that you can only have one public class per file and this file should have the same name than the class. You can just remove the public in front of the definition of the first class. A better way to do would be to make it a static method of the main class.
To solve you second problem you can do this: