Can someone give me an example on how to reverse an inputted string? example is..when you inputted "shoes" the output would be "seohs",,then it wil determine if the inputted string is a Palindrome or not..
This is awful. To begin with, it's not even vaguely related to the dead thread you revived to post it in, so you're on the wrong foot to begin with. Moving along, you really ought to use the code-tags to make life easier for those trying to read your code.
But the real problem is, this is awful code. Why are you mixing swing components and command-line i/o? Why are you using int flags instead of booleans? Why are you using a loop to print a String? Why is this whole thing one long method - how is that "easy to understand"?
And what the hell happened here?
q=JOptionPane.showInputDialog("Do u wish to continue (y/n)?");
if(q.equalsIgnoreCase("n"))
l=JOptionPane.showConfirmDialog(null, "Are you sure?","",JOptionPane.YES_NO_OPTION);
if(l==1)
q="y";
else
break;
} while(q.equalsIgnoreCase("y"));
JOptionPane.showMessageDialog(null,"Thanks for using my prog");
}
Okay, I understand you're a novice and you were trying to convert a CLI program to run in a GUI. But please don't post bad code to answer a question which wasn't asked in a long-dead thread. Okay? Great, glad that's settled.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Skill Endorsements: 3
import java.util.Scanner;
public class sortString {
public static void main(String args[]){
Scanner input=new Scanner(System.in);
String s;
String reverse="";
System.out.println("Enter String:");
s=input.next();
for(int i=0;i<s.length();i++){
reverse=s.charAt(i)+reverse;
}
System.out.println("Reverse String= "+reverse);
}
}
don't revive ancient (dead) threads and even when: don't just hand out code. let them do an effort themselves and help improving their work, instead of just passing your code off as theirs.
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
there are a lot easier ways, too. but that is no reason to revive a thread that should 've died over a year ago.
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
bhahista .. that would indeed work, you do have statements you don't use/need, but hey, if it works, it works, right? but anyway, after three years, if the OP hadn't found a way to do it yet, I'm pretty sure (s)he isn't looking anymore.
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
gauravbit70: allow me to introduce you to a new (still experimental) concept. it's called 'Date'.
you are replying to a thread in which, according to the 'Date' (see how it kicks in?) the last post was almost half a year ago.
that was a post of mine. did you read that? it stated (and I quote)
but anyway, after three years, if the OP hadn't found a way to do it yet, I'm pretty sure (s)he isn't looking anymore.
you want to hear the joke on this? "How to reverse a String" well, actually, you can't. immutable, remember? you just create a new one, the original one won't be reversed anyway.
but still ... my guess is the OP stopped looking for answers about three years ago. maybe we should too.
stultuske
Industrious Poster
4,372 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24
Hello gauravbit70, welcome to DaniWeb.
Don't be put off by Stultuske, he's just having a bit of fun. Your contributions are very welcome here.
Before posting please do check the dates on threads, and please don't just post solutions with no explanations or comments - we want people to be able to learn from what they read here.
J
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
I would say that's a good example of using single-purpose methods methods and well-chosen names. It makes the code so clear that it needs no comments, and it's really easy to read, understand, and verify.
JamesCherrill
... trying to help
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30