1 / 13

Introducción a JAVA

Introducción a JAVA. COMP 250. Estructura de Selección. selection statements Escoger cuál acción ejecutar dependiendo de dos ó más alternativas a evaluar

ona
Télécharger la présentation

Introducción a JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introducción a JAVA COMP 250

  2. Estructura de Selección • selection statements • Escogercuálacciónejecutardependiendo de dos ó másalternativas a evaluar • Las condiciones son expresionesbooleanas, estoes, el resultado de unacomparaciónes un valor booelano (true / false)

  3. Estructura de Selección • Operadores de comparación Observar que el radio de un círculo no puede ser cero ó negativo (menor que cero)

  4. Estructura de Selección • Ejemplo double radius = 1; System.out.println(radius > 0); • El valor a mostrar en el output debesertrue

  5. Estructura de Selección • if statements • One-way if statements • Formato: if (boolean-expression) { statement(s);} false (radius >= 0) true area = radius * radius * PI;System.out.println(“The area for the circle of radius “ + radius + “ is “ + area);

  6. Estructura de Selección • Two-way if statement • Formato: if(boolean-expression) { statement(s)-for-the-true-case; } else { statement(s)-for-the-false-case; } true false Boolean expression Statements for the true case Statements for the false case

  7. Estructura de Selección • Nested if statements if (score >= 90.0) grade = ‘A’; else if (score >= 80.0) grade = ‘B’; else if (score >=70.0) grade = ‘C’; else if (score >= 60.0) grade = ‘D’; else grade = ‘F’;

  8. Estructura de Selección • switch statement T Compute tax for single filers status = 0 break F T Status = 1 Compute tax for married filers break default Default actions

  9. Estructura de Selección • Ejemplo: switch (status) { case 0: compute taxes for single filers; break; case 1: compute taxes for married filers; break; default: System.out.println(“Errors: invalid status”); System.exit(0);

  10. Formatting console output • Formato general: System.out.printf(format, item1, item2, …itemz) Donde format es un string que puede consistir de varios formatos especializados

  11. Formatting console output Ejemplo: int count =5; double amount = 45.56; System.out.printf(“count is %d and amount is %f”, count, amount); Output: count is 5 and amount is 45.560000

  12. Formatting console output

  13. Logical Operators Ejemplos: (asumir que age = 24, gender = ‘F’) !(age > 18) …………………………………………………..false !(gender == ‘M’)…………………………………………..true

More Related