Van icon

JAVA METHODS

Links


    //JAVA STRING METHODS

    
    //1-charAt(n)
    cadena.charAt(1);
    
    //2-substring()
    cadena.substring(0,5);
    
    //3-equals()
    cadena.equals("Hola");
    
    //4-compareTo()
    cadena.compareTo("Hola");
    
    //5-contains()
    cadena.contains("Hola");
    
    //6-isEmpty()
    cadena.isEmpty();
    
    //7-lenght
    cadena.length();
    
    //8-replace()
    cadena.replace("Hola", "Hello");
    
    //9-toCharArray()
    cadena.toCharArray();   
    
    //10-valueOf()
    cadena.valueOf(cadena);
    
    //11-toUpperCase() // toLowerCase();
    cadena.toUpperCase();
    cadena.toLowerCase();
    
    //12-trim()
    cadena.trim();
    
     //13-indexOf()
    cadena.indexOf(cadena);
    


    //JAVA MATH METHODS 


    //1-BASIC OPERATIONS
    public void BasicOperations(){
    //SUMA
    double suma = x + y;

    //RESTA
    double resta = x - y;

    //MULTIPLICACION
    double multiplicacion = x * y;

    //DIVISION
    double division = x / y;
    }


    //2-METHODS
    public void Math_Methods(){
        
        
    //2-Math.pow(x, 2) Potencia
    Math.pow(x, 2); //x elevado a 2

    //3-Math.sqrt(y); Raiz cuadrada
    Math.sqrt(y);

    //4-abs(x)      Returns the absolute value of x
    Math.abs(x);

    //5-ceil(x) 	Returns the value of x rounded up to its nearest integer
    Math.ceil(x);

    //6-floor(x) 	Returns the value of x rounded down to its nearest integer
    Math.floor(x);

    //7-max(x, y) 	Returns the number with the highest value
    Math.max(x, y);

    //8-min(x, y)   Returns the number with the lowest value
    Math.min(x, y);

    //9-round(x)    Returns the value of x rounded to its nearest integer
    Math.round(x);

    //10-random() 	Returns a random number between 0 and 1
    int a, c;
    double b;
        for (a=0; a<100; a++){  //realizo un bucle para contar hasta 100 y generar num en cada vuelta
        b =  Math.random() * (200 -(-100)+1) + (-100); // uso este metodo para generar aleatorios y luego que estén en el rango elegido
        c = (int) b;
        }

    //PAR/IMPAR: controlamos el resto %
    if (x%2 == 0) System.out.println("es par");}