Edward Amankwa

Greenhorn
+ Follow
since Jun 18, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Edward Amankwa

I have an array of integers with values of 1 & 0 how can I write a method to flip the ones to zero and zero to ones like in c++ bitwise ~ with out using the ~
15 years ago
I am actually trying to tie to a scanner and I don't need to read the content of the document
15 years ago
Supposing I am scanning a document, how can I display the scanned document in a viewer and also show the scanned document icon in an open folder.
15 years ago
Thank you again Ken for your explaination. Since I am playing around I am wondering if incresed is initialized this way increased []= {0,0,0,4}.I tried that and got all zero except the last element which is 4. Is there any way to starting iterating from the last element and multiply the both last elements and store the results in the last but one element.
16 years ago
Thank you very much for your help.It is working and I will apprecaite it if you can explain a little further.
16 years ago
What I meant is if last element is 4 in increased[]. This four should be multiplied to the last element in size [] and the result is the value of the last but one in incraesed and it go that way till the last result is put into the first element of increased [].
16 years ago
Let assume the last element has a value of 4, how will I initialize the that element only.
16 years ago
If I use your code the result is all zeros, and I think if I can initialize increased.length-1 the result will change
16 years ago
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);
}
}
16 years ago
How can I multipy elements of two different arrays which are of the same length. However, I know the values for one array but the other I know the value of the last element. To find the values of the other array I have to multiply the last element values of both array and stored them in the last but one value of the array which I don't know the values. For example, for array D and Array C my output should look like this.

C D
3 4 Last element 3*4
4 12 4*12
2 48
2 96
16 years ago
Thank you very much Ernest for your quick reply.
16 years ago
Here is my code and if you can show me how to find the product without the last 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 JLabel [] enter;
private JTextField [] input1;
private JTextField [] input2;
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]);
}

//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 totalSize = 1;
//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());
size[j] = (collectinput2[j]+1)- collectinput1[j];
}
theOutput = "Index\tLower\t Upper\t Size\n";
for (int f=0; f < dim; f++)
{
totalSize *= size[f];// I am stuck here
theOutput += f + "\t"+collectinput1[f] +"\t" + collectinput2[f]+"\t"+size[f]+"\n" ;
}
totalSize = totalSize * 2;
theOutput+="TotalSize\n" + totalSize;
output.setText(theOutput);
}
}
16 years ago
How do I find the product all array elements without the first element
16 years ago
Thanks a lot Marc for your help. Sometime is not easy to see such mistakes.
16 years ago
I have tried the code below, but when run I get zero for total size.
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 JLabel [] enter;
private JTextField [] input1;
private JTextField [] input2;
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]);
}

//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 totalSize = 0;
//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());
size[j] = (collectinput2[j]+1)- collectinput1[j];
}
theOutput = "Index\tLower\t Upper\t Size\n";
for (int f=0; f < dim; f++)
{
totalSize *= size[f];
theOutput += f + "\t"+collectinput1[f] +"\t" + collectinput2[f]+"\t"+size[f]+"\n" ;
}
theOutput+="TotalSize\n" + totalSize;
output.setText(theOutput);
}
}
16 years ago