0

How to a Jumble characters in a string?

I want to to know how can I jumble characters in a string.

16th Nov 2016, 2:49 PM
Nitin Kumar
Nitin Kumar - avatar
1 Respuesta
+ 1
java.util.*; public class jumble { boolean flag; public void search(boolean a[], int b) { if(a[b]==true) { flag=false; } else { flag=true; } } public static void main(String[] args) { Scanner sc=new Scanner(System.in); jumble obj=new jumble(); System.out.println("Enter the string"); String a=sc.nextLine(); int b=a.length(); String result=" "; boolean arr[]=new boolean[b]; boolean flag=true; for(int i=0;i<b;i++) { arr[i]=false; } for(int j=0;j<=b-1;j++) { double c=Math.random()*100; int d=(int) c%b; obj.search(arr, d); if(obj.flag==true) { result=result+Character.toString(a.charAt(d)) ; arr[d]=true; } else { j--; } } System.out.println(result); } }
18th Nov 2016, 5:17 AM
Prarabdh Garg
Prarabdh Garg - avatar