Run the following Java code and explain what it does. Give the resulting image from the code using inputs 3,960 1,234 222,222 13,780

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need it asap please !!!

Will rate your answer!!!

Run the following Java code and explain what it does. Give the resulting image from the code using inputs 3,960 1,234 222,222 13,780

interface ArrayStackADT
{
public void pop();
public void push(Object a);
public void display();
public boolean isEmptyStack();
public boolean isFullStack();

}

class ArrayStackDataStrucClass<T> implements ArrayStackADT
{
// An object of type T is declared
final static int n=100;
T stack[];
int top=-1;
  
// Default constructor
ArrayStackDataStrucClass() {
this.stack = (T[]) new Integer[100];
}
//Overloaded Constructor
ArrayStackDataStrucClass(T obj[]) {
this.stack = obj;
}

  
@Override
public void push(Object obj)
{
T t1= (T) obj;
try
{
if(!isFullStack())
{
stack[++top]=t1;
}
}
catch(Exception e)
{
System.out.println("e");
}
}
  
@Override
public void pop()
{
T popper = null;
if(top<0)
{
System.out.println("Stack underflow");
return;
}
else
{
popper=stack[top];
top--;
//System.out.println("Popped element:" +popper);
}
  
}
  
@Override
public void display()
{
if(!isEmptyStack())
{
String str=" ";
for(int i=0; i<=top; i++)
str=str+" "+stack[i]+" <--";
System.out.println("Elements are:"+str);
}
}
@Override
public boolean isEmptyStack() {
if(top<0)
{
System.out.println("Stack is empty");
return true;
}
return false;
}
@Override
public boolean isFullStack() {
if(top==(n-1))
{
System.out.println(" Stack Overflow");
return true;
}
return false;
}
  
T peek()
{
if(!isEmptyStack())
{
return stack[top];
}
return null;
}
  
  
  
  
}
public class PrimeFactorizationDemoClass {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr={2960,1234,222222,13780};
for(int ii=0;ii<arr.length;ii++)
{
int inputNum = arr[ii];

int num = inputNum;
Integer intObj1[] = new Integer[100];
try {
ArrayStackDataStrucClass<Integer> obj1 = new ArrayStackDataStrucClass(intObj1);
  
int top=-1, i;
  
// Print the number of 2s that divide n
while (num % 2 == 0) {
obj1.push(2);
num /= 2;
top++;
}
  
// num must be odd at this point. So we can
// skip one element (Note i = i +2)
for ( i = 3; i <= Math.sqrt(num); i += 2) {
// While i divides n, print i and divide n
while (num % i == 0) {
obj1.push(i);
num /= i;
top++;

}
}
  
// This condition is to handle the case whien
// num is a prime number greater than 2
if (num > 2)
{
obj1.push(num);
top++;
}
  
System.out.print("Prime Factor for "+inputNum+" is : ");
while(top != -1)
{
System.out.print(obj1.peek() );
if(top != 0)
System.out.print(" * " );
obj1.pop();
top--;
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("");
}
}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education