Advertisement
xlujiax

Untitled

May 7th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. package sentencia;
  2. public class EjemploIF2 {
  3.     public void logica() {
  4.         int x = (int) (Math.random() * 20.0);
  5.         if (aprobar(x)) {
  6.             System.out.println("Su Nota es : " + x);
  7.             System.out.println("Aprueba, muy bien ");          
  8.         }else {
  9.             System.out.println("Su Nota tiene oportunidades de mejora: " + x);
  10.             System.out.println("Lamentablemente desaprueba :v");   
  11.         }          
  12.     }
  13.     public boolean aprobar(int x) {
  14.         boolean aprueba = false;
  15.         if ( x >= 11)
  16.             aprueba = true;    
  17.         return aprueba;
  18.     }  
  19.     public static void main(String[] argus) {
  20.         System.out.println("Dentro del main");
  21.         EjemploIF2 objIf = new EjemploIF2();
  22.         objIf.logica();    
  23.     }
  24. }
  25. ------------------
  26. package sentencia;
  27. import java.util.Scanner;
  28. public class Input01 { 
  29.     public static void main(String[] args) {
  30.         Input01 ej = new Input01();
  31.         ej.logica(); //Eclipse
  32.     }  
  33.     public void logica() {     
  34.         Scanner sc = new Scanner(System.in);
  35.         for (int i = 1; i < 3; i++) {
  36.             System.out.println("Ingrese un numero entero");
  37.             int numero = sc.nextInt();
  38.            
  39.             if (numero%2 == 0)
  40.                 System.out.println("El numero es Par");
  41.             else
  42.                 System.out.println("El numero es ImPar");          
  43.         }
  44.     }  
  45. }
  46. -----------
  47. package sentencia;
  48. import java.util.Scanner;
  49. public class Input02 {
  50.     public static void main(String[] args) {
  51.         Input02 ej02 = new Input02();
  52.         ej02.logica();
  53.     }  
  54.     public void logica() {
  55.         Scanner sc = new Scanner(System.in);
  56.         System.out.println("Ingrese su Nombre ");
  57.         String linea = sc.nextLine();
  58.        
  59.         System.out.println("Longitud \t"+linea.length() );
  60.         System.out.println("Mayusculas \t"+linea.toUpperCase());
  61.         System.out.println("Minusculas \t"+linea.toLowerCase());
  62.         System.out.println("Quitar blancos \t"+linea.trim());
  63.        
  64.         System.out.println("Concatenar \t"+linea.concat("Hola"));
  65.         System.out.println("Indexof \t"+linea.indexOf("Renzo"));
  66.        
  67.         if (linea.contentEquals("Renzo Castillo"))
  68.             System.out.println("Los Strings son identicos");
  69.        
  70.         for (int i = 0; i < linea.length(); i++) {
  71.             System.out.println(linea.substring(i,i+1));
  72.         }
  73.         for (int i = linea.length(); i > 0; i--) {
  74.             System.out.println(linea.substring(i-1,i));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement