How to print some characters from the Ascii table? Java POO

0

I have to print by console the special, numeric, uppercase and lowercase characters of the ASCII table; But it does not print anything. I tried to get the for and only this sign comes out:

for each method that I call in the main. I leave the code that I made.

public class TablaDeAscii {

    private char numeros;
    private char minusculas;
    private char mayusculas;
    private char especiales;


    public TablaDeAscii() {
        this.numeros = numeros;
        this.minusculas = minusculas;
        this.mayusculas = mayusculas;
        this.especiales = especiales;
    }

    public char getNumeros() {
        char numerico=0;
        int contadorN=0;
        for (int i = 0; 32 >= i && i <= 122; i++) {
            if (48 >= numeros && numeros <= 57) {
                contadorN ++;
                numerico+=contadorN;
            }
        }
        return numerico;
    }

    public char getMayusculas() {
        ;
        int contadorMa=0;
        for (int i = 0; 32 >= i && i <= 122; i++) {
            if (65 >= mayusculas && mayusculas <= 90) {
                    contadorMa++;
               mayusculas+=contadorMa;
            }
        }
        return this.mayusculas;
    }

    public char getMinusculas() {
        char minuscula = 0;
        int contadorMi = 0;
        for (int i = 0; 32 >= i && i <= 122; i++) {
            if (97 >= minusculas && minusculas <= 122) {
                contadorMi++;
                minuscula+=contadorMi;
            }
        }
        return minuscula;
    }

    public char getEspecial() {
        char especial = 0;
        int contadorE=0;
        for (int i = 0; 32 >= i && i <= 122; i++) {
            if (32 >= especiales && especiales <= 47) {
                contadorE++;
                especial+= contadorE;
            }
        }
        return especial;
    }
}

public class PruebaAscii {

    public static void main(String[] args) {
        TablaDeAscii tabla1 = new TablaDeAscii();

        System.out.println(tabla1.getEspecial());
        System.out.println(tabla1.getMayusculas());
        System.out.println(tabla1.getMinusculas());
        System.out.println(tabla1.getNumeros());
    }
}
    
asked by computer96 04.12.2018 в 20:41
source

2 answers

2

Modify your for loop, so that it prints to you in the following way:

for (int c=32; c<128; c++) {
    System.out.println(c + ": " + (char)c);
} 
    
answered by 04.12.2018 / 20:44
source
3

I complement the response of @David Davila with this little trick to go through the ascii table without making castings.

public static void main(String[] args) {
    for (char c = 'a'; c < 'z'; c++) {
        System.out.println("Symbol " + c);
    }
}
    
answered by 05.12.2018 в 02:48