Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Programa en java que solicite al usuario una frase, y que el programa
- * cuente cuantas minusculas, mayusculas, numeros y caracteres que no
- * incluyan los anteriores ni los espacios. */
- import java.util.*;
- public class contar_caracteres{
- public static void main (String args[]) {
- String frase = validador();
- contador(frase);
- }
- public static String validador(){
- Scanner tecvalidador = new Scanner(System.in);
- boolean noSirve = true;
- String frase = "";
- while (noSirve){
- System.out.print("Ingrese una frase: ");
- frase = tecvalidador.nextLine();
- noSirve = validaQueNoSeaNula(frase);
- if (noSirve==false){
- noSirve = validaLosEspacios(frase);
- }
- }return frase;
- }
- public static boolean validaQueNoSeaNula(String X){
- if(X.length()==0){
- System.out.println("Error! Frase nula.");
- return true;
- }else{
- return false;
- }
- }
- public static boolean validaLosEspacios(String garro){
- for(int i=0; i<garro.length(); i++){
- if (garro.charAt(i)!=' '){
- return false;
- }
- }System.out.println("Error! Frase contiene solo espacios.");
- return true;
- }
- public static void contador(String garro){
- int c=0, f=0, pene=0, poto=0;
- char x;
- for(int i=0; i<garro.length(); i++){
- x=garro.charAt(i);
- if (x>='0' && x<='9'){
- c++;
- }else if (x>='a' && x<='z'){
- f++;
- }else if (x>='A' && x<='Z'){
- pene++;
- }else if (x!=' '){
- poto++;
- }
- }System.out.println("La cantidad de numeros es: "+c);
- System.out.println("La cantidad de letras minusculas es: "+f);
- System.out.println("La cantidad de letras mayusculas es: "+pene);
- System.out.println("La cantidad de otros caracteres es: "+poto);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement