ok, Im still stuck with this problem...Im using a 2D array to print out a 3x3 spreadsheet but there must be recursion in it. A can do the array, just dont know how to carry on: ie. when the user enters a formula in the input, it shud output the correct answer e.g
1)Sample Input 1 2 3 4 5 6 =A1+A2 =B1+B2 =C1+C2
Sample Output
1 2 3
4 5 6
5 7 9
2)Sample Input John 12 23 David 45 67 Total =B1+B2 =C1+C2
Sample Output
John 12 23
David 45 67
Total 57 90
this is what Ive done so far:
import java.util.Scanner;
class Question1
{
public static void main(String args[])
{
Scanner input= new Scanner(System.in);
int row=3;
int column =3;
String [][]grid= new String [row][column];
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
grid[i][j]=input.next();
System.out.print(grid[i][j]+" ");
}
System.out.println("");
}
//Ive PUT everything else in braces as im not sure how to structure my program...I think i shud use the charAt method to separate the formula and use the IntegerparseInt method to convert the String in2 a interger so that i can add or subtract them, but I have no idea how to put my thoughts into code...i do know that the recursion comes in when using the "=" as a base case then output my spreadsheet as in eg2 where the cells keep on getting referred to another block...
/*public getCell()
for(int i = 0; i<=row; i++)
for(int j=0; j<=column;j++)
{
if (grid[i][j].charAt(0)== '=')
{
public getFormula()
for(int i = 0; i<=row; i++)
for(int j=0; j<=column;j++)
for (i=1;i<=grid.length;i+=3)
if (grid[i][j].charAt(1)=='A')
/* grid[i][j].substring(1,2);
grid[i][j].charAt(1)-'A'
grid[i][j].charAt(2)=
grid[i]=Integer.parseInt(charAt(i)- 'A');
return Integer.parseInt(grid[][])
public getRecursion()
}
}
}*/
}
}

New Topic/Question
Reply




MultiQuote







|