View Single Post
Join Date: Nov 2008
Posts: 8
Reputation: beginner21 is an unknown quantity at this point 
Solved Threads: 0
beginner21 beginner21 is offline Offline
Newbie Poster

Re: pls help w/ this

 
0
  #8
Dec 1st, 2008
alright..
i print now the output that i wanted..
i have a question again..
i want to hide the values of the cards in my output.
here is my modified code:
  1. import java.io.*;
  2. public class Num2
  3. {
  4. public static void main(String[]args)throws IOException
  5. {
  6. BufferedReader a=new BufferedReader(new InputStreamReader(System.in));
  7.  
  8. int r1, c1, r2, c2;
  9. int[][]cards;
  10. cards=new int[4][4];
  11. for(int r=0; r<4; r++)
  12. {
  13. for(int c=0; c<4; c++)
  14. {
  15. cards[r][c]=(int) (Math.random() * 8);
  16. System.out.print(cards[r][c]);
  17. }
  18. System.out.print("\n");
  19. }
  20. for (int r=0; r<4; r++)
  21. {
  22. for (int c=0; c<4; c++)
  23. {
  24. System.out.print("*");
  25. }
  26. System.out.print("\n");
  27. }
  28. System.out.print("\nPlease insert the first card row: ");
  29. r1=Integer.parseInt(a.readLine());
  30. System.out.print("\nPlease insert the first card column: ");
  31. c1=Integer.parseInt(a.readLine());
  32. System.out.print("\nPlease insert the second card row: ");
  33. r2=Integer.parseInt(a.readLine());
  34. System.out.print("\nPlease insert the first card column: ");
  35. c2=Integer.parseInt(a.readLine());
  36. //reveal
  37. for(int r=0; r<4; r++)
  38. {
  39. for (int c=0; c<4; c++)
  40. {
  41. if((r==r1)&&(c==c1))
  42. {
  43. System.out.print(cards[r][c]);
  44. }
  45. else if((r==r2)&&(c==c2))
  46. {
  47. System.out.print(cards[r][c]);
  48. }
  49. else
  50. {
  51. System.out.print("*");
  52. }
  53. }
  54. //match?
  55. if (cards[r1][c1]==cards[r2][c2])
  56. {
  57. }
  58. else
  59. {
  60. System.out.println();
  61. }
  62. }
  63. }
  64. }

the output is:
  1. 5264
  2. 7021
  3. 1741
  4. 1556
  5. ****
  6. ****
  7. ****
  8. ****
  9. Please insert the first card row: 1
  10. Please insert the first card column: 2
  11. Please insert the second card row: 3
  12. Please insert the second card column: 3
  13. ****
  14. **2*
  15. ****
  16. ***6
the values in my output are printed also..
before the 4x4 *;
what should i modify?
Last edited by beginner21; Dec 1st, 2008 at 1:19 am. Reason: code tags
Reply With Quote