Question: /** *@author nada alamer *@version 1.0 */ public class HailStoneSeq{ /** *@param a array to store the sequence *@param i index of array *@param n
/** *@author nada alamer *@version 1.0 */ public class HailStoneSeq{ /** *@param a array to store the sequence *@param i index of array *@param n the number generated */ private int[] a = new int[7]; int i=0; int n=3; /** *@param generate the sequence */ public void generateSeq(int x){ while (n !=1 && x>=1){ a[i] = n; i++; if(n % 2 == 0) { n= n/2;} else { n=3* n + 1; } x--; } a[i] = n; i++; } /** *@param to string final method that print the sequence *@return result the string that contains the sequence */ public final String toString(){ String result= "n= "; for(int j=0; j<=a.length;j++) result=result + a[j] + ", "; return result; } }
/** *@author nada alamer *@version 1.0 */ public class TestAlgo{ public static void main (String args[]){ HailStoneSeq hailtest= new HailStoneSeq(); hailtest.generateSeq(3); System.out.println(hailtest.toString()); } }
Fix the dynamic checking result using a List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
