ing.cip.ivan petrlik azabache. semana 02 control de flujo condicional simple if( condicion) {...

29
ING.CIP .IVAN PETRLIK AZABACHE

Upload: maria-pilar-coronel-gimenez

Post on 02-Feb-2016

232 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

ING.CIP .IVAN PETRLIK AZABACHE

Page 2: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

SEMANA 02

Page 3: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

Control de flujo Condicional Simple

if( condicion) {

//sentencia 1 // sentencia 2 . . }

Page 4: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }
Page 5: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

Condicional Doble

if( condicion) { //sentencia 1 // sentencia 2 } else { //sentencia 3 //sentencia 4 }

Page 6: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }
Page 7: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

Condicional anidada

if( condicion1) { //sentencia 1 // sentencia 2 } else { if(condicion2){ //sentencia3 //sentencia4 } else { . . . // n veces }

}

Page 8: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }
Page 9: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

Selector de opciones(switch-case)

switch( opcion ) { case var1 : { // sentencia1 break; } case var2 : { // sentencia1 break; } default : { // sentencia 3 } }

Page 10: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }
Page 11: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

ESTRUCTURAS REPETITIVAS

Page 12: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

DO- WHILE(HACER-MIENTRAS)

Page 13: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

WHILE (MIENTRAS –HACER)

Page 14: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FOR ( DESDE- HASTA)

Page 15: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

CONTADORES Y ACUMULADORES

Page 16: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

EJERCICIOS PROPUESTOS UTILIZANDO WHILE(MIENTRAS-HACER)

3)MOSTRAR POR PANTALLA LOS NUMEROS DESDE 0 HASTA 15 , HALLAR LA SUMATORIA DE LOS NUMEROS

Page 17: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

UTILIZANDO WHILE(MIENTRAS-HACER)

4 ) Mostrar por pantalla los numeros impares desde 3 hasta 15 , hallar la cantidad de numeros

Page 18: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

UTILIZANDO WHILE(MIENTRAS-HACER)

7)Hallar cuantos son pares e impares del ingreso por teclado de 10 numeros ,Enteros

Page 19: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FOR(DESDE- HACER)

8)Mostrar por pantalla los numeros desde 0 hasta 10

Page 20: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FOR(DESDE- HACER)

9) Mostrar por pantalla la sumatoria de los numeros comprendidos entre 2 hasta 20

Page 21: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FOR(DESDE- HACER) 12) Mostrar 5 veces por pantalla un menu de opciones

con las siguientes caracteristicas :

Al Ingresar una de estas opciones inmediatamente se debera de ejecutar cada alternativa pero en un orden coherente.

Page 22: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

DO-WHILE(HACER-MIENTRAS)

1)Ingresar N numeros por teclado , la cual a medida que se vaya ingresando cada numero se ira almacenando, el programa pedira si deseas seguir Ingresando otro numero, si desea continuar (ingresar el 1 ) en caso contrario (ingresar otro valor)

Page 23: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }
Page 24: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

TIPO DE FUNCIONES

FUNCIONES QUE NO RETORNAN VALOR

FUNCIONES QUE RETORNAN VALOR

Page 25: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FUNCIONES QUE NO RETORNAN VALOR

public static void nombre_Funcion(tipo1 var1,tipo2 var2 , ….){

// declaracion de variables locales

//sentencia 1 // sentencia2

}

Page 26: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FUNCIONES QUE RETORNAN VALOR

public static Tipo_dato nombre_Funcion(tipo1 var1,tipo2 var2 , ….){

// declaracion de variables locales

//sentencia 1 // sentencia2

return var ;

}

Page 27: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

FORMA DE INVOCAR UNA FUNCION

SINTAXIS :

Nombre_Funcion( <parametros>) ;Ejemplo : Sumar(a,b) ; ImprimirDatos( );

Page 28: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

package dominio_aplicacion ; public class nombre_clase {

// declaracion de variables globales

public static void main(String []args ) { funcion1( 56 , 5.4 ); funcion2( ) ; }public static void funcion1 ( int a , double b ) {…………………….. …………………….. }public static int funcion2 ( ){………………..……………..return var; } public nombre_clase ( ) {

} }

Page 29: ING.CIP.IVAN PETRLIK AZABACHE. SEMANA 02 Control de flujo  Condicional Simple if( condicion) { //sentencia 1 // sentencia 2. }

PROPUESTO Diseñe un programa que me permita

implementar un menú de opciones de conversión de unidades de Tiempos:

Convertir Horas a Segundos [ 1 ] Convertir Segundos a Horas [ 2 ] Convertir Horas a minutos [ 3 ] Convertir Minutos a Horas [ 4 ] Convertir Minutos a Segundos [ 5 ] Salir [ 6 ] Sabiendo que se tendra que Ingresar a una de

estas opciones en la cual te pedira el tiempo a convertir , y mostrar

la conversión por pantalla. .