HW Square
package lab7;import javax.swing.*;
public class ArraySquare {
private static int ary[];
private static int x,L;
public ArraySquare()
{
this.ary = new int [Integer.parseInt(JOptionPane.showInputDialog("Please enter the numbers of arrary elements:"))];
for(int r=0; r
ary[r]=Integer.parseInt(JOptionPane.showInputDialog("Please enter number:"));
}
}
public ArraySquare(int[] a)
{
this.ary = new int [a.length];
for(int r=0; r
ary[r]=a[r];
}
}
public static ArraySquare Square( ArraySquare newArrary)
{
ArraySquare square = new ArraySquare(newArrary.ary );
for (int i = 0; i< newArrary.ary.length;i++)
{
square.ary[i] = newArrary.ary[i] * newArrary.ary[i];
// System.out.print(ary[i]+", ");
}
return square;
}
public void toString (ArraySquare square)
{
for(int i=0;i
System.out.print(square.ary[i]+",");
}
System.exit(0);
}
}
---------
package lab7;
public class ArrarySquareDemo {
public static void main(String[] args) {
ArraySquare squareDemo = new ArraySquare();
ArraySquare.Square(squareDemo);
squareDemo.toString(squareDemo);
}
}
----
0 Comments:
張貼留言
<< Home