1. Engineering
  2. Computer Science
  3. for intro to java problem 106 cant figure out why...

Question: for intro to java problem 106 cant figure out why...

Question details
For intro to java problem 10.6, can’t figure out why the error I’m getting is there or how to fix it
111粟/** 13 141 public class Stack0fIntegers { 16 17 * eparan args the command line arguments 19 public static void main(Stringt) args) ( II TODO code application logic here 21 //Problem 10.6 Display The Prime Numbers I1 Create a StackofIntegers StacköfIntegers stack- new StackofIntegers) /1 Find and push all prime numbers less than 120 to stack for (int i 211 120; 1+) if (isPrise(1)) stack.push()i 31 // Displays all the prine numbers less than 120 in decreasing o System.out.printLn while (Istack.enpty)) System.out.println): InAll the prime numbers less than 128 in decreasing order: System.out.print(stack.pop() +) / Return true if n is a prine number public static lisPrine(11) { for (int d 2id n2; d++) 45 return false 47 return true; 1 Next -Select,aA Previous 20 2 3 4 5 6
Start Page x Stackon MyRectangle2DJava x 51 52 private intll elements: private int size public static final int DEFAULT CAPACITY16 *Construct a stack with the default capacity 16 / public StackofIntegers) this (DEFAULT CAPACITY) 57 / Construct a stack with the specified maximum capacity / public StackofIntegers (Int cepacit) 61 elements new inticapacityli * Push a new integer to the top of the stack * public void push(ntau) 641 Θ if (size elements. length) f intu temp = new int [elements. length * 2); System.arraycopy(elements, e, temp, , elements. Length) elements # teep; elements(size++] . value; 73 /s* Return and remove the top element from the stack / public Int pop) t return elements [--size]: /ss Return the top elenent from the stack/ public int peek) return elements[size 11 85 0 Test whether the stack is empty * public soonaan empty() { 0; return size 引 、Previous -Next -Select aA - .* 2 3 4 5 6
731L x Return and remove the top element from the stack / public Int popt) t return elements[-sizel: 78 79 /e* Return the top element from the stack / return elements[size 1]: ฉุ public ■ peek(){ 84 /e* Test whether the stack is empty / public booempty) ( 2 87 return size 0; /* Return the number of elements in the stack/ public getSize() { return size 9기 } -Next -Select iaA.-..園 Previous 脊 2.0 888 FA 15 2 3 4 6
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution