473,385 Members | 2,243 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,385 software developers and data experts.

I'm getting a return statement error

I'm new to Java. I'm getting the following error from my code:
(Palindrome.java:30: error: missing return statement
} // close method)


My code is:

[public class Palindrome { // define class palindrome

public static boolean isPalindrome(String inputWord) { //define method

int rightSide = inputWord.length() -1; // right side

while (leftSide < rightSide) { //loops until middle is found.
if ((inputWord.charAt(leftSide))!= (inputWord.charAt(rightSide))){
return false; // when letters on each side are not equal
// a false value is returned.
} else {
return true; } // if finished, all chars were same

} // close while stmt

} // close method

} // close class ]
Nov 19 '11 #1
4 1632
Leen
22
maybe this is not the error
but r u define the 2 fields : leftSide and rightSide??
Nov 20 '11 #2
Rabbit
12,516 Expert Mod 8TB
It's probably because there exists the possibility that you never return anything.
Nov 21 '11 #3
1. In While loop the condition is
tested first and then the statements are executed if the condition turns out to
be true.
In do while the statements are executed for the first time and then the conditions
are tested, if the condition turns out to be true then the statements are
executed again.

All block in method isPalindrome is not return a value.
Place a return between //close while and //close method.
Dec 19 '11 #4
Leen
22
the first mistake: u check the first and the last letter in ur string ONLY, for example if u have the word: " lamikal "--> the first letter is ' l ' and the last is 'l', but it is not a palindrome...
u will increment the leftSide and decrement the rightSide after each check
Dec 19 '11 #5

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

Similar topics

94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
3
by: Test | last post by:
Sorry, some people may have asked this question before. It is really hard to find relevant articles about this topic on the web using key words. I know it is not recommended to use return...
3
by: Nan Li | last post by:
Hello, all, Does C/C++ ever check the return statement for a non-void function? Look at my simple code below int foo() { } int main()
1
by: Seong-Kook Shin | last post by:
Hi. Just curiocity, Because of pre-ANSI C, it is possible to have a function without specifying return type of a function (which makes the return type 'int', though) and give no 'return'...
3
by: Marlene Stebbins | last post by:
My program has code like this: bigint bigSub(bigint minuend, bigint subtrahend) { bigint bigdiff; bigInit(&bigdiff); if(((cmp_ops(minuend.number, subtrahend.number))==1) && minuend.sign...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
3
by: pedalpete | last post by:
I'm getting a "missing ; before statement" error in javacript I'm surprised i wasn't able to find anything about this on this site. I am not sure why I'm getting this error, everything looks...
4
by: EmilyA | last post by:
Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86. import java.util.ArrayList; ...
3
by: ALi Shaikh | last post by:
Hello, Whenever I run this Program it says "Return statement missing" public class Compare3 { public static Comparable largest (Comparable ob1,Comparable ob2,Comparable ob3) { ...
1
by: Annie Soomro | last post by:
Getting "missing return statement" error for following code: import java.sql.*; public class DatabaseManager{ public static int add(String user,String password)throws Exception{ ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.