Java 402

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java 402 as PDF for free.

More details

  • Words: 185
  • Pages: 1
/** * Ejemplo para ilustrar el uso del operador ternario if-then-else * Para generar la excepción de división por cero, comentar la linea * que asigna este operador a la expresión de la variable f y descomentar * la versión que realiza la división únicamente */ class java402 { public static void main( String args[] ) { int a = 28; int b = 4; int c = 45; int d = 0; // Utilizamos el operador ternario para asignar valores a // las dos variables e y f, que son resultado de la // evaluación realizada por el operador int e = (b == 0) ? 0 : (a / b); int f = (d == 0) ? 0 : (c / d); // int f = c / d; System.out.println( "a = " + a ); System.out.println( "b = " + b ); System.out.println( "c = " + c ); System.out.println( "d = " + d ); System.out.println(); System.out.println( "a / b = " + e ); System.out.println( "c / d = " + f ); } } //------------------------------------------- Final del fichero java402.java

Related Documents

Java 402
June 2020 11
402
June 2020 10
402
November 2019 18
Egr 402
November 2019 19
Novella #402
May 2020 7
Rxd-402
November 2019 18