Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is JAVA Code. Syntaxes in C++ are obviously, a bit different.
- // But Loop syntaxes are pretty much the same for every language;
- // Ami Step gulo jototuku pari bhenge bhenge korsi. Ei jinish bohubhabe kora jabe.
- // Ami matha-mota bhabe korlam time nai dekhe :3
- public class Main
- {
- public static void main(String[] args)
- {
- // PROBLEM 1
- // Print: 2 4 8
- // 2 6 18
- // Creating a 2X3 array
- int outputArray1[][] = new int[2][3];
- // Building the array
- for (int row = 1; row <= 2; row++)
- {
- for (int col = 1; col <= 3; col++)
- {
- if (col == 1)
- outputArray1[row-1][col-1] = 2;
- else
- outputArray1[row-1][col-1] = outputArray1[row-1][col-2] * (row+1);
- }
- }
- // Finally, Print the array
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- System.out.print(outputArray1[i][j] + " ");
- System.out.println();
- }
- System.out.println("\n\nEND OF NO: 1\n\n");
- // PROBLEM 2
- // Print: 12 24 48
- // 4 12 36
- // Creating a 2X3 array
- int[][] outputArray2 = new int[2][3];
- // Prothom shonkha ta 12. Creating a variable to hold it, just to have something to start from.
- int startingValue = 12;
- // Building the array
- for (int row = 1; row <= 2; row++)
- {
- for (int col = 1; col <= 3; col++)
- {
- if (row == 1 && col == 1)
- {
- outputArray2[row-1][col-1] = startingValue;
- continue;
- }
- else if (row != 1 && col == 1)
- {
- outputArray2[row-1][col-1] = startingValue / 3;
- continue;
- }
- outputArray2[row-1][col-1] = outputArray2[row-1][col-2] * (row+1);
- }
- }
- // Finally, Print the array
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- System.out.print(outputArray2[i][j] + " ");
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement