Advertisement
Guest User

carta magica

a guest
Nov 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. package application;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class MainDebug {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. Scanner scn = new Scanner(System.in);
  12. int cartas[] = {1, 2, 3, 4, 5, 6, 7 ,8, 9, 10,
  13. 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
  14. int[] monte = new int[21];
  15. int[] monte1 = new int[7];
  16. int[] monte2 = new int[7];
  17. int[] monte3 = new int[7];
  18. int encontrado = -1;
  19. int next = 0;
  20.  
  21. System.out.println("Digite uma carta (1-21)");
  22. int cartaEscolhida = scn.nextInt();
  23.  
  24. for(int i = 0; i < monte1.length; i++) {
  25. monte1[i] = cartas[i];
  26. monte2[i] = cartas[i+7];
  27. monte3[i] = cartas[i+14];
  28. }
  29. for (int j = 0; j < 3; j++) {
  30.  
  31. for (int i = 0; i < monte1.length; i++) {
  32. if(monte1[i] == cartaEscolhida) {
  33. encontrado = 1;
  34. }
  35. if(monte2[i] == cartaEscolhida) {
  36. encontrado = 2;
  37. }
  38. if(monte3[i] == cartaEscolhida) {
  39. encontrado = 3;
  40. }
  41. }
  42. if(encontrado == 1) {
  43. for (int i = 0; i < monte2.length; i++) {
  44. monte[i] = monte2[i];
  45. monte[i+7] = monte1[i];
  46. monte[i+14] = monte3[i];
  47. }
  48. }
  49. else if(encontrado == 3) {
  50. for (int i = 0; i < monte2.length; i++) {
  51. monte[i] = monte1[i];
  52. monte[i+7] = monte3[i];
  53. monte[i+14] = monte2[i];
  54. }
  55. }
  56. else {
  57. for (int i = 0; i < monte3.length; i++) {
  58. monte[i] = monte1[i];
  59. monte[i+7] = monte2[i];
  60. monte[i+14] = monte3[i];
  61. }
  62. }
  63.  
  64. for (int i = 0; i < monte1.length; i++) {
  65. monte1[i] = monte[next];
  66. next+= 3;
  67. }
  68. next = 1;
  69. for (int i = 0; i < monte2.length; i++) {
  70. monte2[i] = monte[next];
  71. next+= 3;
  72. }
  73. next = 2;
  74. for (int i = 0; i < monte3.length; i++) {
  75. monte3[i] = monte[next];
  76. next+= 3;
  77. }
  78. next = 0;
  79.  
  80. }
  81.  
  82. System.out.println("Monte 1: ");
  83. for (int i = 0; i < monte1.length; i++) {
  84. System.out.print(monte1[i] + " ");
  85. }
  86. System.out.println("");
  87. System.out.println("Monte 2: ");
  88. for (int i = 0; i < monte1.length; i++) {
  89. System.out.print(monte2[i] + " ");
  90. }
  91. System.out.println("");
  92. System.out.println("Monte 3: ");
  93. for (int i = 0; i < monte1.length; i++) {
  94. System.out.print(monte3[i] + " ");
  95. }
  96.  
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement