All Questions
37
questions
-3
votes
2
answers
114
views
how do i populating an array with certain values in random spots JAVA
public static void main(String[] args) {
int castleTiles[][] = new int[8][8];
for(int i = 0; i < castleTiles.length; i++) {
for(int j = 0; j < castleTiles[i].length; ...
-2
votes
2
answers
3k
views
how to get the index of list of list in java
class Result {
public static int diagonalDifference(List<List<Integer>> arr) {
int sum=0,sum1=0;
for(List<Integer> list:arr){
for(Integer ...
1
vote
2
answers
1k
views
Check if the given Matrix has Valid dimensions - JAVA
I want to check if the given Matrix has valid dimensions.
This Matrix Below has Invalid Dim because it does not satisfy Matrix properties
Matrix x = new Matrix(new double[][]{
{ 1.0, ...
0
votes
1
answer
87
views
Java creating a 2d int array which getting bigger inside
I want to create a 2d int array thats getting bigger from the outside to the inside, the first layer should start with 1 and the next layer should be 1 higher.
With n = 3 it should look like this :
...
-2
votes
2
answers
244
views
How can I find the sum of a diagonal in a 2D Matrix?
I'm new to java. How can I find the sum of diagonals (that looks like /) in a 2D Matrix?
Let's say the matrix looks something like this:
4 6 7
2 4 7
5 2 7
The sum of the diagonal(that looks like \...
0
votes
0
answers
32
views
The shape rotation using the transform matrix
I'm trying to write a simple program that will rotate a randomly generated polygon by a given angle. However, this algorithm does not perform the necessary task. Can someone help with solving this ...
0
votes
1
answer
601
views
How to traverse through 2d array and count how many elements are greater than 1 in each row in row major order
I'm writing a method that traverses through a 2d array in row-major order and at the start of each row, I initialize a count variable to zero. In the inner loop, if a value is non-zero I ...
1
vote
2
answers
134
views
Algorithm not showing right output
The Question was:
You are given a binary matrix (i.e. each element of matrix is either 0 or 1) of size n × n. You want to re-arrange 1's in such a way that they form a rectangular region. Note that ...
-3
votes
3
answers
3k
views
Java: Compare elements of 2D array(matrix) in the column And finding row number containing smallest value in that column
I have an array matrix with n rows and s columns. I need to find the row number for each column containing smallest element. for example I have array matrix
double[][]={{2, 3, 4, 6},
{3,...
0
votes
1
answer
297
views
Java: Sum of 2D array where the M[i][j] = (int) i/j
T - number of test cases | 1<=T<=10 and n - number of elements | 1<=n<=1000000
Eg
if (T >= 1 && T <= 10) {
for (int i = 0; i < T; i++) {
int n = sc....
0
votes
2
answers
163
views
Can I get integer values for a 2D array instead of characters?
I was trying to create the simpliest matrix - 2d array and I have trouble with my code, it is kind of working, but not correctly.
Code:
int result = 0;
int[][] matrix = new int[2][2];
for(int ...
0
votes
2
answers
2k
views
Finding the diagonal edges of an 2D array relative to any position - Java
I have a 6x6 array of numbers:
int[][] multi = new int[][]{
{4, 2, 3, 2, 5, 1},
{2, 5, 5, 4, 1, 1},
{2, 4, 6, 7, 2, 4},
{2, 1, 2, 3, 4, 3},
{3, 5, 1, 4,...
0
votes
1
answer
1k
views
Java OOP Changing the position of 2d matrix?
If I have a matrix such as 3x4 with values of
1 2 3 4
5 6 7 8
9 1 2 3
and lets say the user wanted to rotate a column:
Enter column no = 2. Result will be like:
1 6 3 4
5 1 7 8
9 2 2 3
and ...
4
votes
4
answers
2k
views
elements of the matrix above the diagonal
public class Main {
public static void main(String[] args) {
int array[][] = {
{2, 3, 4, 5, 6},
{2, 3, 4, 5, 6},
{2, 3, 4, 5, 6},
...
-4
votes
2
answers
74
views
Doubling a 2-dimensional matrix in Java [duplicate]
I currently have a program that, when asked for an integer from the user, generates a square 2d matrix based on the input (i.e.,.: input of 2 results in a 2x2 grid).
The program then fills this ...