programa Java para imprimir caracteres diferentes utilizados (letras) en una cadena

Este programa va a leer una cadena e imprimir diferentes caracteres / letras usadas en Java.

de impresión diferentes caracteres / letras de una cadena utilizando programa Java

//Java program to print used different characters (letters) in a string.
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("Write something here...: ");
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);
}
}

salida

    
Write something here...:
Hello friends, this is me.
Following characters are used in the input text:
D E F H I L M N O R S T
Total number of different characters are: 12


Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *