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:
public class firstprog { public static 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; } else { if(b>c) return b; else return c; } } public static void main(String args[]) { int a=19; int b=2; int c=1; System.out.println(largest(a,b,c)); } }