public class funk { int largest(int a,int b,int c) if(a>b) if(a>c) return a; else if(b>c) rerotate b; else rerotate c; public course 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 form funk should be defined in its own file.

You are watching: This method must return a result of type int

Why is this so?


*

*

Yes the difficulty is that you have the right to only have actually one public class per file and this file must have the exact same name than the class. You can just remove the public in front of the definition of the first course. A better means to do would be to make it a static technique of the primary class.

To settle you second trouble you deserve to perform this:

public class firstprog public static int largest(int a,int b,int c) if(a>b) if(a>c) rerevolve a; else if(b>c) rerevolve b; else rerotate c; else if(b>c) rerotate 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));
Share
Improve this answer
Follow
edited Nov 4 "11 at 13:47

*

Sampboy
254k7070 gold badges518518 silver badges550550 bronze badges
answered Nov 3 "11 at 14:33
*

lc2817lc2817
3,6321414 silver badges3535 bronze badges
9
| Sjust how 4 more comments
2
Only one public peak level class (a height level class is a course not contained in an additional class) is enabled per .java record.

Define funk in funk.java via no other peak level classes.

Put any other height level classes in their own documents where the file name matches the course name.

Regarding your second question, if you declare an approach to return a specific kind, favor int, then all routes with that strategy need to lead to a rerevolve statement returning a valid value. In your instance, the if statement could not be entered!

What happens if b == a or a ?


Share
Improve this answer
Follow
edited Nov 3 "11 at 14:44
answered Nov 3 "11 at 14:33
*

Jonathon FaustJonathon Faust
12k33 gold badges4747 silver badges6161 bronze badges
3
Add a comment |
1
Are you trying to put multiple classes right into one file? Each class must gain its own .java document via the appropriate name. Also make the first letter of your course top situation, as this is the naming convention.

As an aside, your feature will certainly just work if a is bigger than c. You"ve missed out on some cases.

EDIT: you have the right to have nested classes, but I think you might want to stay ameans from stuff like that for currently.


Share
Improve this answer
Follow
answered Nov 3 "11 at 14:35
G_HG_H
11.6k22 gold badges3333 silver badges7474 bronze badges
Add a comment |
1
In Java public classes must be in sepaprice records via name the exact same as class name.

So put your funk class in funk.java file and also firstprog class in firstprog.java fileOr delete public in funk course, then this class will have default package modifier.


Share
Improve this answer
Follow
edited Oct 6 "15 at 14:39
answered Nov 3 "11 at 14:35
Mariusz PawelskiMariusz Pawelski
19.5k77 gold badges5858 silver badges7474 bronze badges
Add a comment |
0
For your second error, the logic appears to be off a tiny... tbelow is no return statement in the instance wright here b > a.


Share
Improve this answer
Follow
answered Nov 3 "11 at 14:40
LJ2LJ2
57355 silver badges1111 bronze badges
Add a comment |
0
Why is this so?

If you intend "why execute I get this error", it"s because you have actually not put the class in its own file, and also you have to. If you expect "why must I put the class in its very own file", it"s bereason Java says so: one public form (class or interface) per file.

Specifically, "its own" file must have the very same name: the public course funk goes in funk.java, and the public class firstprog goes in firstprog.java.

See more: World Of Guns Gun Disassembly All Guns Hack, World Of Guns: Gun Disassembly 2


Share
Improve this answer
Follow
answered Nov 3 "11 at 14:40
Karl KnechtelKarl Knechtel
52.2k77 gold badges7878 silver badges118118 bronze badges
Add a comment |
0
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) rerotate b; else rerevolve c; rerotate 0; public static void main(String args<>) int a=7; int b=8; int c=9; System.out.println(largest(a,b,c)); Note: you need to add rerevolve statement, because a is not greater then b, so it it not going inside of if block.. In your larget(...) it is expecting rerevolve statement as int.. so you have to add an additional rerevolve statement. then it work ... Cheers ...!!!


Share
Improve this answer
Follow
edited Nov 3 "11 at 15:05
Chadwick
12.2k77 gold badges4747 silver badges6565 bronze badges
answered Nov 3 "11 at 14:52
SrinivasaSrinivasa
1
1
Add a comment |
0
This Eclipse error has actually currently been answered by various other users. Anymethod below is an alternative to uncover the biggest variety of form int

Alternative - Find the biggest integer, making use of stream():

public static int largest(int a, int b, int c) return Arrays.asList(a, b, c).stream().max(Integer::compareTo).get().intValue();Rundown of the error:

Here is the Eclipse error:

The approach have to rerevolve an outcome of kind intReson for error:

Not all problem are taken care of in technique biggest. "Outside" condition "if(a > b)" a "rerevolve an int" is required.

Aleraboriginal - "if statements" making use of Clean code"s principle "early on return"/"eager return":

public static int largest(int a, int b, int c) if(a > b && a > c) rerotate a; if(b > c) return b; return c;
Share
Improve this answer
Follow
edited Sep 5 "20 at 17:56
answered Sep 5 "20 at 17:29
DigitShifterDigitShifter
60144 silver badges1010 bronze badges
Add a comment |
0
During compilation time, your compiler cannot find the parallel else problem of (a>b) that is => if(a




*





Draft saved


Sign up utilizing Facebook


Message as a guest


Name






Not the answer you're looking for? Browse various other inquiries tagged java or ask your own question.





0

4

-2


4028

7185

3624

4229

4389

3351

3791

867

3266

3483









Stack Exchange Network

Stack Overcirculation functions ideal through JavaScript enabled
*

Accept all cookies Customize settings