I am playing around of how to do some multiplication involving arrays. The point is I know all the elements value of size[] and only the last element value of increased[]. Starting from the last values, I should muiltiply both of them and put the result in the last but one element of increased []and do the same till I put the last result in first element
package arrayoffset;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
*
*/
public class arrayOffset extends JFrame implements ActionListener{
int dim = 5;
private String theOutput = "";
private int [] collectinput1 = new int[dim];
private int [] collectinput2 = new int[dim];
private int [] collectinput3 = new int[dim];
private JLabel [] enter;
private JLabel subscript;
private JTextField [] input1;
private JTextField [] input2;
private JTextField [] input3;
private JTextArea output;
/** Creates a new instance of arrayOffset */
public arrayOffset() {
// Collect the number of dimension from user
String num = JOptionPane.showInputDialog("Enter the number of dimension");
dim = Integer.parseInt(num);
Container con = getContentPane();
con.setLayout(new FlowLayout());
//layout components to collect data
enter = new JLabel [dim];
input1 = new JTextField[dim];
input2 = new JTextField[dim];
for(int i = 0; i<dim; i++)
{
enter [i]= new JLabel("Enter the upper and lower bounds for subscript:" + i);
con.add(enter[i]);
input1 [i] = new JTextField(2);
input1 [i].addActionListener(this);
con.add(input1[i]);
input2 [i] = new JTextField(2);
input2 [i].addActionListener(this);
con.add(input2[i]);
}
subscript = new JLabel("Enter a set of subscripts");
con.add(subscript);
input3 = new JTextField[dim];
for(int s=0; s<dim; s++ )
{
input3 [s] = new JTextField(2);
input3 [s].addActionListener(this);
con.add(input3[s]);
}
//add component to display data
output = new JTextArea(10, 25);
output.setEditable(false);
con.add(output);
setSize(450, 400);
setVisible(true);
}
public void actionPerformed(ActionEvent l)
{
int size [] = new int [dim];
int increased []= new int [dim];
//String [] myoutput = l.getActionCommand();
for(int j= 0; j<dim; j++)
{
collectinput1[j] = Integer.parseInt(input1 [j].getText());
collectinput2[j] = Integer.parseInt(input2 [j].getText());
collectinput3[j] = Integer.parseInt(input3 [j].getText());
size[j] = (collectinput2[j]+1)- collectinput1[j];
}/*I am stuck here I will like to multiply size[] and increased [] with the last element of increased being 4.*/
theOutput = "Index\tLower\t Upper\t Size\t Increased\n";
for(int d=0; d < dim; d++)
theOutput += d + "\t"+collectinput1[d] +"\t" + collectinput2[d]+"\t"+size[d]+"\n";
output.setText(theOutput);
}
}