i´m having an issue. I´m trying to remove a row from a 2D array which match a certain condition. I previously created a 2D array using
String [][] T = new String [line][column];
The user can choose the number of lines and column and populate the table with the value of his choice. One of the column must contain prices of items and those prices will be compared to a price limit given by the user and every item below the price must be deleted from the 2D array (the row). I have been told to use array. But here I need to use "for loop" and a 2D table.
So far that s what i have for the "removing part"
public static String[][] deleterow(String[][]T, int priceLimit)
{
// count number of lines matching the condition (used later to redefine the new size)
int count=0;
int priceItem;
for (int i=0; i<T.length;i++)
{
for (int j=3; j<T[i].length;j++) // 4th colomn should contains prices
{
priceItem = Integer.parseInt(T[i][j]);
if (priceItem< priceLimit)
{
count=count+1;
}
}
}
String [][]T3 = new String [T.length-count][];
for (int i=0; i<T.length;i++)
{
for (int j=0; j<T[i].length;j++)
{
priceItem = Integer.parseInt(T[i][j]);
if(priceItem < priceLimit)
{
T3[i][j]=T[i+1][j];
}
else
{
T3[i][j]=T[i][j];
}
}
}
System.out.println(count+" items deleted from the table");
Unfortunately i´m having a problem with the parsing from String to Int here so the code is not going further. What can be improved?