Results 1 to 1 of 1
-
How to Shuffle a particular String
This example program is used to shuffle a particular string.
Java Code:public class Shuffle{ public static void main(String[] args){ String cards="abbckdoeglieha"; System.out.println("Input String = " + cards); cards=shuffle(cards); System.out.println("Shuffled String = " + cards); } static String shuffle(String cards){ if (cards.length()<=1) return cards; int split=cards.length()/2; String temp1=shuffle(cards.substring(0,split)); String temp2=shuffle(cards.substring(split)); if (Math.random() > 0.5) return temp1 + temp2; else return temp2 + temp1; } }
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Help with insertName(String name) and deleteName(String name)
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM -
Help with code "perfect shuffle"
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:25 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks