I'm having a problem with a program so please bare with me. I'm supposed to make it add the rows and columns but i want to use an interface that prompts the user to enter which row/column he wants to add and displays the result. Here is the code for my program. i have many errors so the more help the better thanks......
import java.awt.*;
import javax.swing.JOptionPane;
class kbfirst {
public static void main(String[] args) {
int[][] TwoDimArray = { {10, 20, 25 , 15}, {35, 0, 9, 5}, {45, 25, 55, 50} };
//Prompt the user to enter a string
String r = JOptionPane.showInputDialog(null, "Would you like to add a row or column???");
if (String s1 == "row") {
int x = Integer.parseInt(r);
int x = 0;
else if (s1 == "column");
int y = Integer.parseInt(r);
int y = 1:
}
else {
System.out.println("Try again *** Try using lowercase letters");
}
if (int x == 0) {
//Prompt the user to enter a string
String s = JOptionPane.showInputDialog(null, "You have chosen to add a row. Which row would you like to add row 1,2,3, or 4???");
else if String s == "1";
int chosenrow = Integer.parseInt(s);
chosenrow = 1;
System.out.println("Sum for row number " + chosenrow + "is" Rowtotal );
else if String s == "2";
int chosenrow = Integer.parseInt(s);
chosenrow = 2;
System.out.println("Sum for row number " + chosenrow + "is" Rowtotal );
else if String s == "3";
int chosenrow = Integer.parseInt(s);
chosenrow = 3;
System.out.println("Sum for row number " + chosenrow + "is" Rowtotal );
else if String s == "4";
int chosenrow = Integer.parseInt(s);
chosenrow = 4;
System.out.println("Sum for row number " + chosenrow + "is" Rowtotal );
}
else {
System.out.println("What did you do wrong????? Try again");
}
if (int y == 1) {
//Prompt the user to enter a string
String t = JOptionPane.showInputDialog(null, "You have chosen to add a column. Which column would you like to add column 1,2, or 3");
else if String t == "1";
int chosencolumn = Integer.parseInt(t);
chosencolumn = 1;
System.out.println("Sum for column number " + chosencolumn + "is" Coltotal);
else if String t == "2";
int chosencolumn = Integer.parseInt(t);
chosencolumn = 2;
System.out.println("Sum for column number " + chosencolumn + "is" Coltotal);
else if String t == "3";
int chosencolumn = Integer.parseInt(t);
chosencolumn = 3;
System.out.println("Sum for column number " + chosencolumn + "is" ColSum);
}
else {
System.out.println("What did you do wrong????? Try again");
}
}
int ColSum(int Coltotal) {
int newrow;
int newcolumn;
int chosencolumn;
int Coltotal;
for (int newcolumn = 0; newcolumn < TwoDimArray[chosencolumn].length; newcolumn++) {
int Coltotal = 0;
for (int newrow = 0; newrow < TwoDimArray.length; newrow++);
Coltotal = Coltotal + TwoDimArray[newrow][newcolumn];
return ColTotal;
}
}
int RowSum(int Rowtotal) {
int row;
int chosenrow;
int column;
int Rowtotal;
for (int row = 0; row < TwoDimArray[chosenrow].length; row++) {
int Rowtotal = 0;
for (int column = 0; column < TwoDimArray.length; column++);
Rowtotal = Rowtotal + TwoDimArray[row][column];
return Rowtotal;
}
}
}
else {
System.out.println("What did you do wrong????? Try again");
}
}
^
int ColSum(int Coltotal) {
int newrow;
**My error message is on that bracket illegal start of operation***