【CareerCup】Chapter 1 | Arrays and Strings
1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?
1 //1.1 2 //Implement an algorithm to determine if a string has all unique characters. 3 //What if you can not use additional data structures? 4 import java.util.*; 5 public class Chaper1_1 { 6 public static void main(String[] args){ 7 int count =1; 8 Scanner input=new Scanner(System.in); 9 System.out.println("Input the String: "); 10 String check = input.next(); 11 byte[] srtbyte = check.getBytes(); 12 for (int i=0;i<=srtbyte.length-1;i++){ 13 for(int j=i+1;j<=srtbyte.length-1;j++){ 14 if(srtbyte[i]==srtbyte[j]){ 15 System.out.println("The string doesn't have all unique characters."); 16 count = 0; 17 } 18 } 19 } 20 if (count!=0) System.out.println("The string has all unique characters"); 21 } 22 23 }

浙公网安备 33010602011771号