Results 1 to 3 of 3
- 08-29-2008, 07:16 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 7
- Rep Power
- 0
Two diM aRRay and add rows and columns....
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......
else {Java Code: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; } } }
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***Last edited by filly444; 08-29-2008 at 08:42 PM.
- 08-29-2008, 09:28 PM #2
When posting error please post all of the text without editting.
Looks like you have mis-matched {}s.
If you are using an IDE it can help you find {} pairs.
Otherwise you must go thru them one pair at a time until you find the mis-match.
One technique is to start at the inside and work out.
Make a copy of the program to work on. As you pair the {}s delete them and their contents.
Eventually you'll find the problem.
Another technique is print the program and use a pen, drawing a line to connect each pair.Last edited by Norm; 08-29-2008 at 09:31 PM.
- 08-30-2008, 05:24 PM #3
Member
- Join Date
- Aug 2008
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Deleting All rows in the JTable
By surot in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:44 AM -
Using Columns With JTextField
By The Evil Genius in forum AWT / SwingReplies: 1Last Post: 03-17-2008, 01:01 AM -
Fetching rows from DB
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:23 AM -
display rows in jtable
By osval in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:54 PM -
Problems with JSF (columns)
By Peter in forum JavaServer Faces (JSF)Replies: 2Last Post: 07-04-2007, 06:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks