Advertisement
Guest User

Ooyshee_Problem

a guest
Dec 1st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // This is JAVA Code. Syntaxes in C++ are obviously, a bit different.
  2. // But Loop syntaxes are pretty much the same for every language;
  3. // Ami Step gulo jototuku pari bhenge bhenge korsi. Ei jinish bohubhabe kora jabe.
  4. // Ami matha-mota bhabe korlam time nai dekhe :3
  5.  
  6.  
  7. public class Main
  8. {
  9. public static void main(String[] args)
  10. {
  11. // PROBLEM 1
  12. // Print: 2 4 8
  13. // 2 6 18
  14.  
  15. // Creating a 2X3 array
  16. int outputArray1[][] = new int[2][3];
  17.  
  18. // Building the array
  19. for (int row = 1; row <= 2; row++)
  20. {
  21. for (int col = 1; col <= 3; col++)
  22. {
  23. if (col == 1)
  24. outputArray1[row-1][col-1] = 2;
  25. else
  26. outputArray1[row-1][col-1] = outputArray1[row-1][col-2] * (row+1);
  27. }
  28. }
  29.  
  30.  
  31. // Finally, Print the array
  32. for (int i = 0; i < 2; i++)
  33. {
  34. for (int j = 0; j < 3; j++)
  35. System.out.print(outputArray1[i][j] + " ");
  36. System.out.println();
  37. }
  38.  
  39.  
  40. System.out.println("\n\nEND OF NO: 1\n\n");
  41.  
  42.  
  43.  
  44. // PROBLEM 2
  45. // Print: 12 24 48
  46. // 4 12 36
  47.  
  48. // Creating a 2X3 array
  49. int[][] outputArray2 = new int[2][3];
  50.  
  51. // Prothom shonkha ta 12. Creating a variable to hold it, just to have something to start from.
  52. int startingValue = 12;
  53.  
  54.  
  55. // Building the array
  56. for (int row = 1; row <= 2; row++)
  57. {
  58. for (int col = 1; col <= 3; col++)
  59. {
  60. if (row == 1 && col == 1)
  61. {
  62. outputArray2[row-1][col-1] = startingValue;
  63. continue;
  64. }
  65. else if (row != 1 && col == 1)
  66. {
  67. outputArray2[row-1][col-1] = startingValue / 3;
  68. continue;
  69. }
  70.  
  71. outputArray2[row-1][col-1] = outputArray2[row-1][col-2] * (row+1);
  72. }
  73. }
  74.  
  75.  
  76. // Finally, Print the array
  77. for (int i = 0; i < 2; i++)
  78. {
  79. for (int j = 0; j < 3; j++)
  80. System.out.print(outputArray2[i][j] + " ");
  81. System.out.println();
  82. }
  83.  
  84.  
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement