Created
May 22, 2014 18:36
-
-
Save MarioPerezEsteso/691969b719c28bd95c15 to your computer and use it in GitHub Desktop.
Cálculo del valor absoluto de un entero.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int abs (int numero) { | |
return numero > 0 ? numero : -numero; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int valor_absoluto_de_a = Math.abs(a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValorAbsoluto { | |
public static int abs (int numero) { | |
return numero > 0 ? numero : -numero; | |
} | |
public static void main(String[] args) { | |
int a = 10, b = -20, a_abs, b_abs; | |
a_abs = abs(a); | |
b_abs = abs(b); | |
System.out.println("Valores absolutos: |"+a+"| = "+a_abs+" <><><> |"+b+"| = "+b_abs); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValorAbsoluto { | |
public static void main(String[] args) { | |
int a = 10, b = -20, a_abs, b_abs; | |
a_abs = Math.abs(a); | |
b_abs = Math.abs(b); | |
System.out.println("Valores absolutos: |"+a+"| = "+a_abs+" <><><> |"+b+"| = "+b_abs); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment