Results 1 to 3 of 3
  1. #1
    filly444 is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default 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......
    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;
    				}
    			}	
    }
    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***
    Last edited by filly444; 08-29-2008 at 08:42 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,562
    Rep Power
    23

    Default

    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.

  3. #3
    filly444 is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default

    I'm using JCreator. I made a couple of changes to the program and posted it again. I figured it was a missed bracket but i just can't find it. I'm gonna try your suggestions and see if i can find the problem thanks

Similar Threads

  1. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:44 AM
  2. Using Columns With JTextField
    By The Evil Genius in forum AWT / Swing
    Replies: 1
    Last Post: 03-17-2008, 01:01 AM
  3. Fetching rows from DB
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:23 AM
  4. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:54 PM
  5. Problems with JSF (columns)
    By Peter in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 07-04-2007, 06:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •