Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2D Array problem

 
Tracey Morohunfola
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new in Java and creating a GUI that accepts 3 users input simultaneously (double values from 3 textfield) .
My array is double array[][] = new array[3][3];

My question is
1. How do I store those 3 inputs on every click of the add button to display as a 2D array in a textArea
2. Also calculate the sum of values in array[0][0], array[1][0], and array[2][0]

Thanks
 
puneeth poduri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
please add an action listener to the add button

if button variable is "addButton"

then

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking how to add three numbers together?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know why your previous post was overlooked; I suspect you posted it in an inappropriate location. Welcome to the Ranch, even though it is late .

[Pedantic mode]There is no such thing as a 2D array in Java™. Only arrays of arrays.[/Pedantic mode]
Get a piece of paper, and a pencil and (most important ) an eraser, and write down prices [0][0] = 1.23, prices[0][1] = 2.34, prices[0][2] = 3.45, and then add the other rows. Now see if you can work out how to add the three together. Once you see what you are doing, on paper, it will be easy to convert that to code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
puneeth poduri wrote:hi,
please add an action listener to the add button . . .
I think you have misunderstood the problem. Look at this thread.
 
Tracey Morohunfola
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I make the program to allow three users to put in their meal prices

If I run this, it only allows one input and displays it as 3 input in the array


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic