Saturday, 7 September 2013

java program to check whether a string is made up of unique characters or not ..

/*java program to check whether a string is made up of unique characters or not ..*/


       

import java.io.*;
public class P11 {
 public static void main(String args[]) {
  boolean[] ch = new boolean[256];

  String name = "gaurv##";

  for (int i = 0, val; i < name.length(); i++) {
   val = name.charAt(i);
   if (ch[val]) {
    System.out.println("string is not unique");
    return;
   } else {
    ch[val] = true;
   }
  }
  System.out.println("string is unique");
 }
}

       
 

No comments:

Post a Comment