Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2008, 08:16 PM
Member
 
Join Date: Aug 2008
Posts: 7
Rep Power: 0
filly444 is on a distinguished road
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......
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 09:42 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 08-29-2008, 10:28 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
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 10:31 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-30-2008, 06:24 PM
Member
 
Join Date: Aug 2008
Posts: 7
Rep Power: 0
filly444 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 08:56 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org