miércoles, 11 de marzo de 2020

ejercicio 6

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package metodo;

/**
 *
 * @author roque rocha metodo
 */
public class Metodos {

     /**
     * @return
     */
    public int metodoEntero() {//Metodo publico que regresa valor
        int suma =5+5;//
        System.out.println("El resultado de la suma: "+suma);
        return suma;// Calor de retorno
    }
    public int metodoResta(){
        int resta =5-5;//Se declara la variable y se hace la operacion
        System.out.println("El resultado de la resta: "+resta);
        return resta;
    }
      public int metodoMultiplicacion(){
        int multiplica =40*40;
        System.out.println("El resultado de la multiplicacion : "+multiplica);
        return multiplica;
    }
      public int metodoDivision(){
        int division =300/21;
        System.out.println("El resultado de la division : "+division);
        return division;
    }
        public static void main(String[] args) {
            int resultado;
            int resultado2;//Variable
            int resultado3;
            double resultado4;//variable con decimal
            Metodos obj=new Metodos();//Creacion del objeto
            resultado=obj.metodoEntero();//Llamar al metodo usando el objeto
            resultado2=obj.metodoResta();
            resultado3=obj.metodoMultiplicacion();
            resultado4=obj.metodoDivision();
            System.out.println("El resultado de la suma fuera de la clase es: "+resultado);
            System.out.println("El resultado de la resta fuera de la clase es: "+resultado2);
            System.out.println("El resultado de la multiplicacion fuera de la clase es: "+resultado3);
            System.out.println("El resultado de la division fuera de la clase es: "+resultado4);
        // TODO code application logic here
    }
 
}

jueves, 5 de marzo de 2020

5

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package comparar.cadenas;

/**
*
* @author conalep
*/
public class CompararCadenas {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       String cadena1 = new String("Hola");//crear el objeto cadena 1 y dandole un valor el valor hola
       String cadena2 = new String("Hola");//crear el objeto cadena 2 y dandole un valor el valor hola
       if(cadena1.equals(cadena2))//compara cadena 1 con cadena 2
       { System.out.println("Cadenas iguales");//salida
       }
       String cadena3 = new String("Hola");//crear el objeto cadena 3 y dandole un valor el valor hola
       String cadena4 = new String("HOLA");//crear el objeto cadena 4 y dandole un valor el valor hola
       if(cadena3.equalsIgnoreCase(cadena4))//comparar las cadenas ignorando las mayusculas y minusculas
       {System.out.println("Cadenas iguales");
       }
       String cadena5 = new String("Hola");//crear el objeto cadena 5 y dandole un valor el valor hola
       String cadena6 = new String("Lola");//crear el objeto cadena 6 y dandole un valor el valor lola
       if(cadena1.compareTo(cadena2)==0)//
      System.out.println("Cadena 5 y 6 son iguales");
      else
      if(cadena5.compareTo(cadena6)<0)
          System.out.println("Cadena5 va antes que cadena 2");
      else
      if(cadena5.compareTo(cadena6)>0)
          System.out.println("Cadena6 va despues que cadena 1");
      }
   
       
      // TODO code application logic here
   }
 

4

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejercicio.pkg4;
import java.util.Scanner;
/**
*
* @author G ustavo Delgado Diaz de Leon
*/
public class Ejercicio4 {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
 
long falta,numeroInvertido,resto;
System.out.println("Ingresa un numero");
 long numero=sc.nextLong();

while(numero<=0);
 falta=numero;
 numeroInvertido=0;
 resto=0;

resto=falta%10;

falta=falta/10;
numeroInvertido=numeroInvertido*10+resto;

while(falta!=0)
{
resto=falta%10;
numeroInvertido=numeroInvertido*10+resto;
falta=falta/10;
}

if(numeroInvertido==numero)
System.out.println("El numero es capicua\n");
else
System.out.println("El numero no es capicua\n");
       // TODO code application logic here
   }

}

jueves, 27 de febrero de 2020

3

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programa.pkg2;
import java.util.Scanner;
/**
*
* @author Delgado Gustavo
*/
public class Programa2 {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println("Captura el nombre: ");
        String f=sc.next();
       System.out.println("Captura el apellido paterno: ");
        String j=sc.next();
        System.out.println("Captura el apellido materno: ");
        String n=sc.next();
       System.out.println("Captura la edad: ");
        byte k=sc.nextByte();
       System.out.println("Captura el genero: ");
        String p=sc.next();
       System.out.println("Sus datos son : ");
       
       System.out.println(j+ " "+n+" "+f );
       
       if(k>=18){
         System.out.println("sr o Sra");  
       }
       if(k>=13 && k<=17){
         System.out.println("Joven o Srita");  
       }
      if(k<=12){
         System.out.println("niño o niña ");  
       }
       
      int año=2020-k;
      System.out.println("usted nacio en el año:  "+año);  
     
       // TODO code application logic here
   }
   
}

2

 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package manejo.de.cadenas;

/**
 *
 * @author Delgado Gustavo
 */
public class ManejoDeCadenas {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
        String nom;//Objeto tipo cadena
        char extraido;//Variable tipo char
        int longuitud;//Variable tipo entero
        nom="Esto es una cadena de texto";//Inicianilazando el objeto nom
       System.out.println(nom);//Imprecion de el objeto
       longuitud=nom.length();//Asignacion de la longuitud de nom
       System.out.println("La longuitud de la cadena es "+longuitud);//Imprecio de la variable longuitud
       extraido=nom.charAt(13);//Extrae caracter numero 13
       System.out.println("El carcter extraido de la cadena es;"+extraido);//Imprecion de a variable extraido
       char [] destino = new char[20];//Crear un vector de caracteres llamado destino
       try{
           nom.getChars(12, 18, destino,0);//Extrae caracteres de 12 a 18 y los en el vector destino
           System.out.println(destino);//Imprime el vector destino
       }
       catch (Exception ex){//atrapa el error de las lineas de try
     
           System.out.println(ex);
        // TODO code application logic here
    }
 
    }

}

1


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tiposdedatos;
import java.util.Scanner;
/**
 *
 * @author Delgado Gustavo
 */
public class TiposDeDatos {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println("Delgado Diaz de Leon Gustavo");
       
       System.out.println("valor en variable tipo entero");
       int x=sc.nextInt();
       System.out.println("ciclo FOR");
       for(int j=1;j<=5;j++) {
           System.out.println(x);
       }
           
       System.out.println("valor en variable tipo short");
       short y=sc.nextShort();
       System.out.println("ciclo FOR");
       for(int j=1;j<=7;j++)
           {
           System.out.println(y);
       }
           
       System.out.println("valor en variable tipo long");
       long s=sc.nextLong();
        System.out.println("ciclo FOR");
       for(int j=1;j<=10;j++){
           System.out.println(s);
       }
           
       System.out.println("valor en variable tipo byte");
       byte r=sc.nextByte();
        System.out.println("ciclo FOR");
       for(int j=1;j<=5;j++){
           System.out.println(r);
       }
           
       System.out.println("valor en variable tipo cadena");
       String  o=sc.next();
        System.out.println("ciclo FOR");
       for(int j=1;j<=5;j++){
           System.out.println(o);
       }
       
       System.out.println("valor en variable tipo doble");
       double m=sc.nextDouble();
        System.out.println("ciclo FOR");
       for(int j=1;j<=5;j++){
           System.out.println(m);
       }
       System.out.println("valor en variable tipo boolean");
       boolean p=sc.nextBoolean();
       System.out.println("ciclo FOR");
       for(int j=1;j<=5;j++){
           System.out.println(p);
       }
           
        // TODO code application logic here
    }
   
}