1 1AUTOR: EDER CHAVEZ ACHA
2 public int wrong(){ int i; return i+5; } Las variables si se tienen que inicializar o marca el siguiente error al momento de compilar: ¿Cuándo no de inicializan? CORRECCION VARIABLES 2AUTOR: EDER CHAVEZ ACHA
3 Automáticamente cambia el tipo de un dato a otro cuando es pertinente. Por ejemplo: Pasar de int a long Pasar de int a long void moldeos() { int i = 100; long l = (long)i; long l2 = (long)200; } MOLDEO DE OPERADORES “” MOLDEO DE OPERADORES “casting” 3AUTOR: EDER CHAVEZ ACHA
4 Pasar de int a float Pasar de int a float void moldeos() { int i = 100; float f = (float)i; }RESULTADO=100.0 MOLDEO DE OPERADORES “casting” 4AUTOR: EDER CHAVEZ ACHA
5 MOLDEO DE OPERADORES “casting” Pasar de char a int Pasar de char a int void moldeos() { char c='A'; int n; n=(int)c;}RESULTADO=65 5AUTOR: EDER CHAVEZ ACHA
6 MOLDEO DE OPERADORES “casting” Pasar de int a String Pasar de int a String void moldeos() { String s= (String)i; }RESULTADO: Ejemplo_3.java:34: inconvertible types found : int required: java.lang.String String s= (String)i; String s= (String)i; void moldeos() { Int i=64; String s=""+i; } RESULTADO: 64 6AUTOR: EDER CHAVEZ ACHA
7 MOLDEO DE OPERADORES “casting” Pasar de String a int Pasar de String a int void moldeos() { String s=“hola"; int d=Integer.parseInt(s); }RESULTADO: Exception in thread "main"java.lang.NumberFormatException: For input string: “hola" at java.lang.NumberFormatException.forInput String(Unknown Source) at java.lang.NumberFormatException.forInput String(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Ejemplo_3.main(Ejemplo_3.java:39) at Ejemplo_3.main(Ejemplo_3.java:39) void moldeos() { String s="10"; int d=Integer.parseInt(s); } RESULTADO: 10 7AUTOR: EDER CHAVEZ ACHA
8 MOLDEO DE OPERADORES “casting” Pasar de int a byte Pasar de int a byte //rango de byte -128 127 byte b; int in=256; b=(byte)in;RESULTADO=0 |--------------------------------TRUNCA--------------------------------| 8AUTOR: EDER CHAVEZ ACHA
9 ERRORERROR Error de precisión. Error de precisión. void moldeos() {System.out.println(1-0.1-0.1-0.1);}RESULTADO=0.7000000000000001 9AUTOR: EDER CHAVEZ ACHA
10 Estructura general: Ejemplo: Int c[];//declara el arreglo c= new int[4];//crea el arreglo ---------------------------------------------------- float[] diametros={1.1.f,2.2f,3.3f,4,4f}; ARREGLOSARREGLOS Tipo nombre_variable []; 10AUTOR: EDER CHAVEZ ACHA
11 ARREGLOSARREGLOS c= new int[5]; Inicializar: Numerios->0 Numerios->0 Booleanos->false Booleanos->false Clases->null Clases->null 11AUTOR: EDER CHAVEZ ACHA
12 ARREGLOSARREGLOS Valor inicial. 12AUTOR: EDER CHAVEZ ACHA
13 Conjunto de datos el mismo tipo, organizado en 2 o mas columnas y 1 o mas renglones(matriz o tabla). ¡Arreglos de arreglos! ¡Arreglos de arreglos! ARREGLOS BIDIMENCIONALES Tipo [][]nombre_variable=new Tipo [Renglones][Columnas]; 13AUTOR: EDER CHAVEZ ACHA
14 Ejemplo Ejemplo int [][] mints=new int [3][4]; ARREGLOS BIDIMENCIONALES 14AUTOR: EDER CHAVEZ ACHA
15 ARREGLOS BIDIMENCIONALES 15AUTOR: EDER CHAVEZ ACHA
16 ARREGLOS BIDIMENCIONALES 16AUTOR: EDER CHAVEZ ACHA
17 Ejemplo Ejemplo int [][] mints={{1,2,,3},{91,92,93,94},{2001,2002}}; ------------------------------------------------------------------ int b[][]; b=new int[2][]; b[0]=new int[5]; b[1]=new int[3]; ARREGLOS BIDIMENCIONALES 17AUTOR: EDER CHAVEZ ACHA
18 ARREGLOS MULTIDIMENCIONALES 3 Dimensiones. int equipos[][][]=new int [4][4][4]; 4 4 4 18AUTOR: EDER CHAVEZ ACHA
19 OPERADORES DE ASIGNACION 19AUTOR: EDER CHAVEZ ACHA
20 CONDICIONALESCONDICIONALES if( ){ * } if( ){ * }else{ * } 20AUTOR: EDER CHAVEZ ACHA
21 CONDICIONALESCONDICIONALES switch(){case:*break;case:*break;default:*break;} 21AUTOR: EDER CHAVEZ ACHA
22 for(;;){*}while(){*}do{* } while( ); CICLOSCICLOS 22AUTOR: EDER CHAVEZ ACHA