Skip to content

Instantly share code, notes, and snippets.

@vignarajj
Created January 29, 2019 08:10
Show Gist options
  • Save vignarajj/c4987ad8c968ebbfa6ab852713d20c20 to your computer and use it in GitHub Desktop.
Save vignarajj/c4987ad8c968ebbfa6ab852713d20c20 to your computer and use it in GitHub Desktop.
Print the characters in String not repeated.
package javaproblems;
import java.util.Scanner;
public class PrintDiffChar {
public static void main(String[] args) {
String text;
int count;
char ch;
Scanner SC=new Scanner(System.in);
System.out.println("Type your words : ");
text = SC.nextLine();
//converting string into upper case
text = text.toUpperCase();
count = 0;
System.out.println("Following characters are used in the input text ");
for ( ch = 'A'; ch <= 'Z'; ch++ ) {
int i; //character index in string
for ( i = 0; i < text.length(); i++ ) {
if ( ch == text.charAt(i) ) {
System.out.print(ch + " ");
count++;
break;
}
}
}
System.out.println("\nTotal number of different characters are " + count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment