Balls to reusable / modular code!
class Progrm1{
public static void main(String[] args)throws Exception{
for (int i=1; i<101;i++)
if (i%2==0)
System.out.println(i + "\t" + Math.sqrt(i) + "\t" + Math.pow(Math.sqrt(i),Math.sqrt(i)));
}
}
class EvenNumbers
{
public static int lowerLimit;
public static int upperLimit;
public static int terms;
public static int evenCount=0;
public static int[] evenArray;
public static double[] evenRootArray;
public static double[] evenRootPowerRootArray;
EvenNumbers(int lower, int upper) throws NumberFormatException
{
if (lower >= upper) throw new NumberFormatException();
this.lowerLimit = lower;
this.upperLimit = upper;
this.terms = upper-lower;
}
int setEvenArray()
{
this.evenArray = new int[this.terms];
for (int loop = this.lowerLimit; loop <= this.upperLimit; loop++)
{
if (loop%2==0)
{
this.evenArray[evenCount]= loop;
this.evenCount++;
}
}
return this.evenCount;
}
void setEvenRootArray()
{
this.evenRootArray = new double[this.evenCount];
for (int loop = 0; loop <>
{
this.evenRootArray[loop]= Math.sqrt(this.evenArray[loop]);
}
}
void setEvenRootPowerRootArray()
{
this.evenRootPowerRootArray = new double[this.evenCount];
for (int loop = 0; loop <>
{
this.evenRootPowerRootArray[loop]= Math.pow(this.evenRootArray[loop],this.evenRootArray[loop]);
}
}
}
public class Program1
{
public static void main(String[] args) throws Exception
{
int lower = 1;
int upper = 101;
EvenNumbers eve = new EvenNumbers(lower, upper);
int terms = eve.setEvenArray();
eve.setEvenRootArray();
eve.setEvenRootPowerRootArray();
printArrays(eve.evenArray, eve.evenRootArray, eve.evenRootPowerRootArray, terms);
}
static void printArrays(int[] array1, double[] array2, double[] array3, int terms)
{
for (int loop = 0; loop <>
{
System.out.println(array1[loop] + "\t" + array2[loop] + "\t" + array3[loop]);
}
}
}
public static void main(String[] args)throws Exception{
for (int i=1; i<101;i++)
if (i%2==0)
System.out.println(i + "\t" + Math.sqrt(i) + "\t" + Math.pow(Math.sqrt(i),Math.sqrt(i)));
}
}
class EvenNumbers
{
public static int lowerLimit;
public static int upperLimit;
public static int terms;
public static int evenCount=0;
public static int[] evenArray;
public static double[] evenRootArray;
public static double[] evenRootPowerRootArray;
EvenNumbers(int lower, int upper) throws NumberFormatException
{
if (lower >= upper) throw new NumberFormatException();
this.lowerLimit = lower;
this.upperLimit = upper;
this.terms = upper-lower;
}
int setEvenArray()
{
this.evenArray = new int[this.terms];
for (int loop = this.lowerLimit; loop <= this.upperLimit; loop++)
{
if (loop%2==0)
{
this.evenArray[evenCount]= loop;
this.evenCount++;
}
}
return this.evenCount;
}
void setEvenRootArray()
{
this.evenRootArray = new double[this.evenCount];
for (int loop = 0; loop <>
{
this.evenRootArray[loop]= Math.sqrt(this.evenArray[loop]);
}
}
void setEvenRootPowerRootArray()
{
this.evenRootPowerRootArray = new double[this.evenCount];
for (int loop = 0; loop <>
{
this.evenRootPowerRootArray[loop]= Math.pow(this.evenRootArray[loop],this.evenRootArray[loop]);
}
}
}
public class Program1
{
public static void main(String[] args) throws Exception
{
int lower = 1;
int upper = 101;
EvenNumbers eve = new EvenNumbers(lower, upper);
int terms = eve.setEvenArray();
eve.setEvenRootArray();
eve.setEvenRootPowerRootArray();
printArrays(eve.evenArray, eve.evenRootArray, eve.evenRootPowerRootArray, terms);
}
static void printArrays(int[] array1, double[] array2, double[] array3, int terms)
{
for (int loop = 0; loop <>
{
System.out.println(array1[loop] + "\t" + array2[loop] + "\t" + array3[loop]);
}
}
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home