Guest User

Untitled

a guest
Aug 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. String mensaje;
  7. String user;
  8.  
  9. user = "Camilo";
  10. mensaje = "Hakim>>\n\tHola, dame un número entero ?\n" + user + ">>\n\t";
  11. System.out.println(mensaje);
  12.  
  13. Scanner teclado = new Scanner(System.in);
  14. int num;
  15.  
  16. num = teclado.nextInt();
  17.  
  18. // condición simple
  19. if (num < 100) { System.out.println("Hakim>>\n\t ese número es menor a 100");
  20. }
  21.  
  22. if ((num % 2) == 0){ //condición simple con caso contrario
  23. System.out.println("Hakim>>\n\tEs par");
  24. }
  25. else{
  26. System.out.println("Hakim>>\n\tEs impar");
  27. }
  28.  
  29. if (num > 0){ //condición con caso contrario y caso por defecto CASCADA
  30. System.out.println("Hakim>>\n\tY es positivo");
  31. }else if (num<0){
  32. System.out.println("Hakim>>\n\tY es negativo");
  33. }else {
  34. System.out.println("Hakim>>\n\tY es igual a cero");
  35. }
  36.  
  37. mensaje = "Hakim>\n\tAhora, jugaremos cara o cruz\n";
  38. mensaje = mensaje + "\tVoy a generar un número aleatorio entre 0 y 1\n";
  39. mensaje = mensaje + "\tSi el número es <0.500 será cara\n";
  40. mensaje = mensaje + "\tSi el número es >= 0.500 será cruz\n";
  41. mensaje = mensaje + "\tPresiona 1 para apostar por cara y 2 por cruz\n";
  42. mensaje = mensaje + "\tQue elijes?\n" + user + ">>\n\t";
  43. System.out.println(mensaje);
  44. num = teclado.nextInt(); //ingresa el usuario un número
  45.  
  46. Random Ale = new Random(); //se genera un número alteatorio del 0 al 1
  47. double numAle;
  48. numAle = Ale.nextDouble();
  49. System.out.printf("Hakim>>\n\tEl número aleatorio es: %4.3f" ,numAle);
  50.  
  51. if ( numAle <0.500){ //condición ANIDADA
  52. System.out.println("\n\tO sea, Cara! ");
  53. if (num == 1){
  54. System.out.println("\n\tTu ganas! ");
  55.  
  56. }
  57. else {
  58. System.out.println("\n\tYo gané! ");
  59. }
  60. }
  61. else{
  62. System.out.println("\n\tO sea, Cruz!");
  63. if (num == 2){
  64. System.out.println("\n\tTu ganas!");
  65.  
  66. }
  67. else{
  68. System.out.println("\n\tYo gané!");
  69. }
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment