Why is it showing error???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is it showing error????

import Java. until. Scanner; class abx { static boolean plain(String w) { int i; char x; String m=" "; for(i=w.length();i>0;i--) { x=w.charAt(i); m=m+x; } if(m==w) return true; else return false; } public static void main (String args[]) { Scanner sc=new Scanner(System.in); String s; String c=" "; int i, lo=0; char t; System. out. println("enter a sentence"); s=sc.nextLine(); for(i=0;i<s.length();i++) { t=s.charAt(i); if(t==' ') c=c+s.substring(lo,i+1); } if(plain(c) System. out.print(c); lo=i+1; } }

9th Dec 2017, 1:17 PM
priyanshi
priyanshi - avatar
20 Answers
+ 2
You can chk my codes, and find easier ways to find a Palindrome
9th Dec 2017, 1:50 PM
Meharban Singh
Meharban Singh - avatar
9th Dec 2017, 1:50 PM
Meharban Singh
Meharban Singh - avatar
+ 2
Anytime.
9th Dec 2017, 1:51 PM
Meharban Singh
Meharban Singh - avatar
+ 1
I am not sure what your program aims to accomplish.
9th Dec 2017, 1:39 PM
Meharban Singh
Meharban Singh - avatar
+ 1
Oh, you mean Palindrome, Lemme look at the code again
9th Dec 2017, 1:46 PM
Meharban Singh
Meharban Singh - avatar
+ 1
This is a completely wrong code, it will not print anything except "enter a senetence"
9th Dec 2017, 1:49 PM
Meharban Singh
Meharban Singh - avatar
0
import java.util.Scanner; j is small, its util not until. main(String args[]) , you missed ] if(plain(c)) , you missed )
9th Dec 2017, 1:23 PM
Meharban Singh
Meharban Singh - avatar
0
oh Ya... I've corrected it while making in computr but still it's showing error. thanks for this and tell more errors
9th Dec 2017, 1:25 PM
priyanshi
priyanshi - avatar
0
error is Java. Lang. StringIndexOutOfBoundsException: String index out of range: 5(in Java. Lang.String) what does it mean?????? 😁
9th Dec 2017, 1:27 PM
priyanshi
priyanshi - avatar
0
I edited my previous message, chk it again
9th Dec 2017, 1:27 PM
Meharban Singh
Meharban Singh - avatar
0
thanks... I've corrected but still no result. the same error as mentioned
9th Dec 2017, 1:30 PM
priyanshi
priyanshi - avatar
0
It means that your string has length less than what you demand, thats why it runs out of bound.
9th Dec 2017, 1:36 PM
Meharban Singh
Meharban Singh - avatar
0
so.... how to correct it???? tell plse
9th Dec 2017, 1:37 PM
priyanshi
priyanshi - avatar
0
You need to do is, for(i = w.length() - 1; i >= 0; i--) at line 9, according to question.
9th Dec 2017, 1:37 PM
Meharban Singh
Meharban Singh - avatar
0
thanks.. it has run but on typing an arms no. result is yet no one why so
9th Dec 2017, 1:40 PM
priyanshi
priyanshi - avatar
0
it's actually to find all Armstrong no. in a sentence. like Ada, weew etc. I downloaded this prog from net and ran it on computer
9th Dec 2017, 1:42 PM
priyanshi
priyanshi - avatar
0
Sorry, I don't know whats an Armstrong number.
9th Dec 2017, 1:43 PM
Meharban Singh
Meharban Singh - avatar
0
it is a word which is same from starting as well as end eg-ere, ertyytre, Anna etc
9th Dec 2017, 1:45 PM
priyanshi
priyanshi - avatar
0
it's being download from net am not getting what's actually is the error
9th Dec 2017, 1:50 PM
priyanshi
priyanshi - avatar
0
all right... thx ...
9th Dec 2017, 1:51 PM
priyanshi
priyanshi - avatar