473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Getting Return Error

Hello, Whenever I run this Program it says "Return statement missing"
Expand|Select|Wrap|Line Numbers
  1. public class Compare3 {
  2.  
  3.    public static Comparable largest (Comparable ob1,Comparable ob2,Comparable ob3)
  4.     {
  5.  
  6.         if(ob1.compareTo(ob2)>0)
  7.         {
  8.             if(ob1.compareTo(ob3)>0)
  9.                 return ob1;
  10.             else if(ob1.compareTo(ob3)<1)
  11.                 return ob3;
  12.            }
  13.            else 
  14.                return ob2;
  15.  
  16.  
  17.  
  18.     }
  19.  
  20.  
  21.  
  22. }
Dec 2 '08 #1
3 1093
JosAH
11,448 Expert 8TB
You don't want to run this program but you want to compile it and the compiler is complaining. You should've included its error diagnostic message verbatim (including the line number where the error was diagnosed).

The compiler is complaining because of this line:
Expand|Select|Wrap|Line Numbers
  1. else if(ob1.compareTo(ob3)<1) 
  2.  
... because it isn't clever enough to see that if an integer is not > 0 that it is supposed to be < 1; according to the compiler that test might fail and then nothing else is returned from your method. That test is superfluous so remove it an just leave in the 'else' part.

kind regards,

Jos
Dec 3 '08 #2
hsn
237 100+
there must be a return value outside the if statement. so if the program didn't enter the if statement there is a return .

regards
hsn
Dec 3 '08 #3
JosAH
11,448 Expert 8TB
@hsn

You fell for the lousy indentation trap; there is a return statement at the outermost level.

kind regards,

Jos
Dec 3 '08 #4

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

Similar topics

0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
1
by: vijaykumars | last post by:
+-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.