Comp Programming 1
Comp Programming 1
Comp Programming 1
import java.util.*;
int n1;
int n2;
int d1;
int d2;
int sumN=0;
int newDeno=0;
int whole=0;
n1=sc.nextInt();
d1=sc.nextInt();
n2=sc.nextInt();
d2=sc.nextInt();
if(d1==d2){
sumN=n1+n2;
newDeno=d1;
else{
newDeno=d1 * d2;
n1 = n1 *(newDeno/d1);
n2 = n2 * (newDeno/d2);
sumN = n1 + n2;
int gcd=1;
gcd=x;
sumN /=gcd;
newDeno /=gcd;
if(whole==0)
else
}
A java class named Exer1.java is compiled. After doing so, which of the following
files is produced?
Select one:
a. Exer1.class
b. exer1.class
c. exer1.java
d. exer1
Feedback
Question 4
Not answered
Marked out of 1.00
Flag question
Question text
Question 5
Not answered
Marked out of 2.00
Flag question
Question text
Question 6
Not answered
Marked out of 1.00
Flag question
Question text
Question 7
Not answered
Marked out of 1.00
Flag question
Question text
Which of the following signature is valid for the main method entry point in a java
application?
Select one:
a. public static void main(String[] args)
b. public static void main(String args)
c. public static void main(string[] args)
d. public void main(String[] args)
Feedback
Question 8
Not answered
Marked out of 1.00
Flag question
Question text
Question 9
Not answered
Marked out of 1.00
Flag question
Question text
Question 10
Not answered
Marked out of 1.00
Flag question
Question text
String is a primitive data type.
Select one:
a. Yes
b. No
c. Maybe
Feedback
Question 11
Not answered
Marked out of 1.00
Flag question
Question text
Question 12
Not answered
Marked out of 1.00
Flag question
Question text
Question 13
Not answered
Marked out of 1.00
Flag question
Question text
Which of the following signatures is valid for the main method() entry point in an
application?
Select one:
a. public static void main(String [] arg)
b. public void main(String [] arg)
c. public static int main(String [] arg)
Feedback
Question 14
Not answered
Marked out of 1.00
Flag question
Question text
Question 15
Not answered
Marked out of 1.00
Flag question
Question text
Question 16
Not answered
Marked out of 1.00
Flag question
Question text
Variable names in Java can start with a letter, an underscore (_), or a dollar sign
($).
Select one:
True
False
Define a class named MobilePhone with the attributes brand name, model, color
and price. Define 3 constructors - the first one is the default constructor, the
second one initializes all data members and the third one gives an initial value to
the brand name Apple, model iPhone XR and price to 54250 while allowing color
to be initialized by the user. Also, write a display method that prints in this
manner:
Brand: Samsung
Model: S10
Color: Black
Price: 53300.0
Write a method updatePrice that updates the price of the mobile phone. The
method accepts a price. If the value of the price is negative the price must be
deducted with the value. But if positive price must be added with the value. It will
not allow update of price if will result to a negative value for price.
//constructors
public MobilePhone(){}
this.brand = brand;
this.model = model;
this.color = color;
this.price = price;
this("Apple","iPhone XR",color,54250.00);
}
//setter methods
this.brand = brand;
this.model = model;
this.color = color;
this.price = price;
//getter methods
return brand;
return model;
return color;
return price;
}
public void display(){
if (price > 0)
this.price +=price;
else{
this.price -=Math.abs(price);
Write a class Animal with the following attributes: name, age, height and weight
Provide constructors: (1)initialize all attributes and (2) initialize all attributes except age
with default to 1 (3) default constructor
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
this.name=name;
this.age=age;
this.height=height;
this.weight=weight;
return name;
}
public int getAge(){
return age;
return height;
return weight;
return "("+name+","+age+","+height+","+weight+")";
System.out.println(a1);
String accountName;
String accountNumber;
double balance;
public BankAccount(){}
setAccountName(name);
accountNumber = account;
balance = balc;
if(name.contains(" ")){
accountName = name;
}else{
accountNumber = account;
balance = balc;
return accountName;
return accountNumber;
return balance;
balance += balc;
return false;
}else{
balance -= balc;
return true;
this.balance -= balc;
obj.balance += balc;
cashCheck
o cash check and debit balance
the attribute minimum - minimum maintaining balance for a checking account.
• the attribute charge - the amount charged if balance < minimum balance. The
amount charged will be deducted from the balance if after cash check the balance
is less than the minimum balance.
For cash check – the payee is whom you issue the check. Cash check is only
allowed if there is enough money in the account.
• Minimum – maintaining balance of the checking account. There is a charge if
balance is less than the maintaining balance.
class BankAccount {
String accountName;
String accountNumber;
double balance;
public BankAccount(){}
public BankAccount(String account, String name, double balc){
setAccountName(name);
accountNumber = account;
balance = balc;
if(name.contains(" ")){
accountName = name;
}else{
accountNumber = account;
balance = balc;
return accountName;
return accountNumber;
return balance;
}
balance += balc;
return false;
}else{
balance -= balc;
return true;
this.balance -= balc;
obj.balance += balc;
public SavingsAccount(){
this.interestRate = 0;
};
this.interestRate = interestRate;
this.interestRate = interestRate;
if(interestRate == 1040){
return 0.2;
}else{
return interestRate;
interestRate = super.balance*interestRate;
super.balance += interestRate;
balance -= balc;
}else{
System.out.printf("false\n");
return false;
double min;
double charge;
CheckingAccount(){};
this.min = min;
this.charge = charge;
}
this.min = min;
this.charge = charge;
return min;
return charge;
if(amt<=super.balance){
}
Copy and Paste your three classes here.
Implement method input. This method will create objects. See the picture below
as a guide for the values.
your input method must:
create 2 objects for Savings( objectA, objectB) and 1 object for checking (objectC)
perform a withdraw(objectA) and deposit(objectB) for savings object
transfer funds from objectA to objectB (transfer from objectA to objectB)
perform cashCheck for objectC
After all the operations, call the toString method of each class. refer to the
sample output.
class BankAccount {
String accountName;
String accountNumber;
double balance;
public BankAccount(){}
setAccountName(name);
accountNumber = account;
balance = balc;
if(name.contains(" ")){
accountName = name;
}else{
balance = balc;
return accountName;
return accountNumber;
return balance;
balance += balc;
return false;
}else{
balance -= balc;
return true;
}
this.balance -= balc;
obj.balance += balc;
public SavingsAccount(){
this.interestRate = 0;
};
this.interestRate = interestRate;
this.interestRate = interestRate;
}
public double getInterest(){
if(interestRate == 1040){
return 0.2;
}else{
return interestRate;
interestRate = super.balance*interestRate;
super.balance += interestRate;
super.balance += balc;
balance -= balc;
}else{
System.out.printf("false\n");
return false;
double min;
double charge;
CheckingAccount(){};
this.min = min;
this.charge = charge;
this.min = min;
this.charge = charge;
return min;
return charge;
}
if(amt<=super.balance){
object1.withdraw(1000);
object2.deposit(5500);
object1.fundTransfer(object2, 2000);
System.out.println(object1);
System.out.println(object2);
object3.balance += 200;
System.out.println(object3);
}
It is a term used to refer to a method which has the same name as the class name.
Select one:
a. toString method
b. setter method
c. getter method
d. constructor
Feedback
Question 2
Partially correct
Flag question
Question text
/*create a class Product with the following attributes: String pName, int quantity,
String category and float price. Encapsulate the fields. */
static void
public Answer
Product{
private
Answer
String pName;
Answer
private
int quantity;
Answer
private
float price;
private
Answer
String category;
public Product
Answer
(){
}
public Product(String pName,int quantity,float price,String category){
this.pName = pName;
setQuantity
Answer
(quantity);
setPrice
Answer
(price);
Answer
setCategory
(category);
}
public void setQuantity(int quantity){
//minimum quantity is 10 if invalid set it to 10
if(quantity < 10)
10
this.quantity = Answer
else
quantity
this.quantity = Answer
}
public void setPrice(float price){
//no negative price
//price is zero if invalid input
<
if(price Answer
0)
this.price = 0;
else
this.price = price;
}
public void setCategory(String category){
//category must be either of this values
"Beverages","Meat","Dairy","Detergent" if invalid assign it to "Others"
String listCategory[] = {"Beverages","Meat","Dairy","Detergent"};
boolean check=false;
; x++)
equals
if(listCategory[x].Answer
(category) == true)
break;
if(check == false)
this.category ="Others" ;
else
this.category = category;
}
public int getQuantity
Answer
(){ return quantity;}
Answer
public float getPrice
Question 3
Incorrect
Flag question
Question text
Method overriding means a subclass redefines a method of its parent class with
the same name, return type but with different number of arguments.
Select one:
True
False
Feedback
Question 4
Incorrect
Flag question
Question text
Which of the following is the type of file created after the source code is correctly
compiled?
Select one:
a. .class
b. .java
c. .exe
Feedback
Question 5
Correct
Question text
Select one:
a. True
b. False
Feedback
Question 6
Incorrect
Flag question
Question text
Feedback
Question 7
Incorrect
Question text
What will happen when you compile and run the following java code?
public class MyClass{
int i;
public static void main(String[] args){
System.out.println(i);
}
}
Select one:
a. An error message will be displayed which says variable i might not have been
initialized.
Feedback
The correct answer is: Non-static variable i cannot be referenced from a static context.
Question 8
Correct
Flag question
Question text
a. super
b. final
c. static
d. this
Feedback
Question 9
Incorrect
Flag question
Question text
Define a class Name which has three data members: firstname, middle initial and
lastname. Write two constructors - (1) default constructor and (2) a constructor
that allows the initialization of all attributes. Encapsulate. Override toString that
prints in this format (John S. Doe) and equals method.
Define another class Person which has Name, age and gender(possible values: M
or F). Write three constructors - (1) default constructor, (2) a constructor that
allows the initialization of all attributes, and (3) a constructor that allows the
initialization of name and gender while setting age automatically to
25. Encapsulate the fields. Override toString that prints in this format :
Name:John S. Doe
Age:20
Gender:M
NOTE: DO NOT WRITE MAIN METHOD.
For example:
Test Result
Answer:(penalty regime: 0, 0, 0, 0, 0, 0, 40 %)
1
//do not write public in defining your class
Feedback
Syntax Error(s)
__tester__.java:11: error: cannot find symbol
Name name = new Name("John",'S',"Doe");
^
symbol: class Name
location: class __tester__
__tester__.java:11: error: cannot find symbol
Name name = new Name("John",'S',"Doe");
^
symbol: class Name
location: class __tester__
__tester__.java:12: error: cannot find symbol
Person p = new Person(name,20,'M');
^
symbol: class Person
location: class __tester__
__tester__.java:12: error: cannot find symbol
Person p = new Person(name,20,'M');
^
symbol: class Person
location: class __tester__
4 errors
Question author's solution (Java):
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
}
}
public class Person{
private Name name;
private int age;
private char gender;
public Person(){}
public Person(Name name, int age, char gender){
this.name=name;
this.age = age;
this.gender=gender;
}
public Person(Name name, char gender){
this.name=name;
this.age = 25;
this.gender=gender;
}
public void setName(Name name){
this.name=name;
}
Incorrect
Question 10
Incorrect
Question text
a. create
b. class
c. new
d. new()
Feedback
Question 11
Correct
Flag question
Question text
Which of the following signatures is valid for the main method() entry point in an
application?
Select one:
Feedback
Question 12
Incorrect
Flag question
Question text
Feedback
Question 13
Incorrect
Flag question
Question text
True
False
Feedback
Question 14
Incorrect
Flag question
Question text
a. private
b. constant
c. static
d. final
Feedback
Question 15
Incorrect
Mark 0.00 out of 1.00
Flag question
Question text
a. const
b. final
c. constant
Feedback
Question 16
Correct
Flag question
Question text
Select one:
Feedback
The correct answer is: After compiling a java program, a class file is generated.
Question 17
Correct
Flag question
Question text
Which of the following is the correct way to declare an array of 5 integers in java?
Select one:
Feedback
Question 18
Partially correct
Question text
a.
By changing the name of the class.
d.
By replacing overloading from overriding.
Feedback
The correct answers are: By placing overriding method into subclass., By changing the
arguments.
Question 19
Incorrect
Question text
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
public class Main{
Feedback
Syntax Error(s)
Main.java:15: error: cannot find symbol
sum += array[i];
^
symbol: variable sum
location: class Main
Main.java:16: error: cannot find symbol
average = sum / a;
^
symbol: variable sum
location: class Main
Main.java:19: error: cannot find symbol
System.out.printf("Sum is: %.2f", sum);
^
symbol: variable sum
location: class Main
3 errors
Question author's solution (Java):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.*;
public class Sample{
public static void main(String a[]){
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
int array[]=new int[n];
for(int x=0; x<array.length; x++){
array[x]=sc.nextInt();
}
int sum=0;
for(int value: array)
sum+=value;
System.out.println("Sum is: "+sum);
double ave=n;
ave = sum/ave;
System.out.printf("Average is: %.2f",ave);
}
}
Incorrect
Question 20
Correct
Flag question
Question text
Which of the following output commands appends a newline at the end of the data
output?
Select one:
a. Sytem.out.print();
b. Sytem.out.println();
c. Sytem.out.printf();
Feedback
Question 21
Correct
Flag question
Question text
a. Abstract Class
b. Interface
c. Object
d. Variable
Feedback
Question 22
Incorrect
Flag question
Question text
Feedback
Question 23
Partially correct
Mark 0.50 out of 2.00
Flag question
Question text
c. int
d. boolean
e. Integer
Feedback
Question 24
Incorrect
Flag question
Question text
/*Assume MyPoint is already defined having two data members - x and y; getter
methods - getX() and getY...
Use Math.PI not 3.14*/
public class MyCircle{
MyPoint c, p ;
public MyCircle(){}
public MyCircle(Answer
MyPoint c, MyPoint p
){
this.c = c;
this.p = p;
}
;
}
public int getDiameter(){
getRadius() * 2
return Answer
;
}
public double getArea(){
Math.PI * Math.pow (getRadius(),2)
return Answer
;
}
public double getCircumference(){
2 * Math.PI * getRadius()
return Answer
;
}
public String toString(){
return "Area : "+ getArea() +
"\nCircumference : " + getCircumference();
}
Hourly Employee
Note:
Class Person is already loaded in this activity. No need to add the class in your
code.
For example:
public Employee() {}
super(name,address,age);
this.companyName = companyName;
companyName = compName;
}
public String getCompanyName(){
return companyName;
System.out.println("Name : "+getName());
System.out.println("Address : "+getAddress());
System.out.println("Age : "+getAge());
public HourlyEmployee(){}
public HourlyEmployee(String name,String address,int age,String compName,int
hoursWorked,double rate){
super(name,address,age, compName);
this.hoursWorked = hoursWorked;
this.rate = rate;
super(name,address,age, compName);
hoursWorked = 0;
rate = 0;
this.hoursWorked = hoursWorked;
this.rate = rate;
return hoursWorked;
return rate;
}
if(rate == 550.98)
return 22039.2;
else
return 36900.0;
/////////////////////////////
CommissionEmployee class
Note:
Person and Employee class are already in this activity. No need to add those
classes in your code.
For example:
class CommissionEmployee extends Employee {
private float regularSalary; //fixed monthly salary
//CONSTRUCTORS
public CommissionEmployee() {}
public CommissionEmployee(String name,String address, int age,String cName, float regSal, int
nItems,
float commission){
regularSalary = regSal;
itemSold = nItems;
commissionRate = commission;
//SETTERS
//GETTERS
double total;
commissionRate *= itemSold;
total = regularSalary+commissionRate;
return total;
System.out.println("Name : "+getName());
System.out.println("Address : "+getAddress());
System.out.println("Age : "+getAge());
}
Write a class that would match a string. The class has method match with String
as a return type. It accepts two inputs: the phrase/sentence string (text) and the
pattern string (word). This method finds the first (or all) instances of the pattern in
the text and changes that word in all uppercase and return the new phrase.
Method countOccurence accepts a phrase/sentence and a pattern string and
returns its number of occurrences.
Add a main method that will allow the user to input the phrase/sentence and
pattern. Call method match and countOccurence. See test case below.
import java.util.*;
class MatchString{
this.text = text;
this.pattern = pattern;
String match(){
int countOccurence(){
int count = 0;
if(word.equalsIgnoreCase(pattern)){
count++;
}
return count;
}
One Dimensional Arrays Quiz
by CodeChum Admin
Create a program that accepts a positive odd integer input then create an integer array
with a size equal to the inputted number.
Using loops, add integer values into the array by asking for a user input repeatedly until
the last allocable index of the array.
Traverse the array and print the elements in the following example:
import java.util.Scanner;
class Main {
int size,num = 0;
size = scan.nextInt();
arr[i] = scan.nextInt();
System.out.print("{");
System.out.print(arr[i]);
System.out.print("}");
Rotate the array 90 degrees counter-clockwise and print the new result.
import java.util.Scanner;
class Main {
int rows,cols;
cols = scan.nextInt();
rows = scan.nextInt();
matrix[i][j] = scan.nextInt();
System.out.print("\n");
System.out.print("\n");
import java.util.Scanner;
import java.text.DecimalFormat;
class Main {
int size,sum = 0;
Scanner scan = new Scanner(System.in);
size = scan.nextInt();
arr[i] = scan.nextInt();
sum += arr[i];
In the main function, write a program that accepts an integer input which would serve as
an inclusive stopping point of a loop iteration that starts at the value of 1.
If the number that loops through the range is divisible by either 2 or 3, then call the
banner function, otherwise just print the number.
import java.util.Scanner;
System.out.println("CodyChum");
if (i % 2 == 0 || i % 3 == 0){
banner();
} else {
System.out.println(i);
In the main function, call the askInput function and store the returned value in a variable and
print the variable.
import java.util.Scanner;
public class Main{
System.out.print(ask);
This function prints a right triangular pattern of letter 'T' based on the value of n. The top of the
triangle starts with 1 and increments by one down on the next line until the integer n. For each
row of in printing the right triangle, print "T" for n times.
import java.util.Scanner;
System.out.print('T');
System.out.println();
System.out.print("Enter N: ");
int n = scan.nextInt();
generatePattern(n);
In the main function, write a program that asks for a character input and assign it to a
character variable. Call the oppCase function by passing in the character variable and
assign the returned value to a variable. Afterwards, print the variable.
import java.util.Scanner;
return Character.toLowerCase(a);
} else {
return Character.toUpperCase(a);
char a = scan.next().charAt(0);
System.out.println(oppCase(a));
Fibonacci Sequence is a series of numbers in which each number is the sum of the two
preceding numbers.
In the main function, write a program that accepts an integer input. Call the sequence
function by passing the inputted integer.
import java.util.Scanner;
first = second;
second = next;
int n = scan.nextInt();
sequence(n);
import java.util.*;
class Main{
int count = 0;
int place = 1;
int bin = 0;
while(num != 0){
num /= 2;
arr[count] = bin;
count++;
x++;
System.out.print("Enter X: ");
int x = scan.nextInt();
System.out.print("Enter Y: ");
int y = scan.nextInt();
display(x, y);
}
import java.util.*;
class Main{
arr[rows][cols] = scan.nextInt();
}
System.out.println();
int sum = 0;
int temp = 0;
temp += arr[rows][cols];
sum += total[rows];
Methods Quiz
by CodeChum Admin
Create a class named Triangle that has attributes base and height. Ask for inputs for these
attributes. Then, create a method printArea() that prints the area of the triangle.
import java.util.*;
class Triangle{
this.base = base;
this.height = height;
Constructors Quiz
by CodeChum Admin
Create a class named Person that has the attributes:
First name - String
Last name - String
Gender - String
Age - Integer
Address - String
Create two constructors: one that accepts the first name and last name only and one
that accepts all attributes. Accept inputs for all attributes and create two objects that use
each constructor. Print their attributes.
import java.util.*;
class Person{
this.firstName = firstName;
this.lastName = lastName;
public Person(String firstName, String lastName, String gender, int age, String address){
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.age = age;
this.address = address;
System.out.println("Gender: ");
System.out.println("Age: ");
System.out.println("Address: ");
scan.nextLine();
System.out.println();
System.out.println("Object 1");
p2.objOne();
System.out.println();
System.out.println("Object 2");
p2.objTwo();
}
}
Inheritance Quiz
by CodeChum Admin
Instructions:
1. Construct a class called “Rectangle”. A “Rectangle” has both a length and a width (both
positive integers). Access to them should be only inside the class and within the
inheritance hierarchy. Then implement the following:
• lone constructor that accepts two integers for the length and the width. Prints “Rectangle
Constructor”
• getters and setters
• area - prints “Rectangle Area” and returns the area of the rectangle
• perimeter - prints “Rectangle Perimeter” and returns the perimeter of the rectangle
1. Create a class called “Square”. The square is a rectangle. Therefore, have Square inherit
from Rectangle. Square construction prints “Square Constructor” and accepts one integer
which is the length of a side. The version of the area and perimeter of Square prints
“Square Area” and “Square Perimeter”, respectively.
import java.util.*;
class Rectangle{
System.out.println("Rectangle Constructor");
this.length = length;
this.width = width;
this.length = length;
}
this.width = width;
return length;
return width;
System.out.println("Square Constructor");
System.out.println("Square Area");
System.out.println("Square Perimeter");
side.getArea();
System.out.println();
side.getPerimeter();
import java.util.Scanner;
class Circle{
setRadius(radius);
this.radius = radius;
System.out.print("Radius: ");
System.out.println();
circle.display();
}
}
Encapsulation Quiz
by CodeChum Admin
A rectangle can be formed given two points, the top left point and the bottom right point.
Assuming that the top left corner of the console is point (0, 0), the bottom right corner of
the console is point (MAX, MAX) and given two points (all “x” and “y” coordinates are
positive), you should be able to draw the rectangle in the correct location, determine if it
is a square or a rectangle, and compute for its area, perimeter and center point. To be
able to do this, you should create a class Point (that has an x-coordinate and a y-
coordinate). Also, create another class called Rectangle. The Rectangle should have 2
points, the top left and the bottom right. You should also implement the following
methods for the Rectangle:
display() - draws the rectangle on the console based on the
sample
area() - computes and returns the area of a given rectangle
perimeter() - computes and returns the perimeter of a given
rectangle
centerPoint() - computes and returns the center point of a given
rectangle
isSquare() - checks whether a given rectangle is a square or
not.
import java.util.Scanner;
System.out.print("Enter x: ");
int x = scan.nextInt();
System.out.print("Enter y: ");
int y = scan.nextInt();
System.out.println();
if(shape.isSquare() == true){
System.out.println("SQUARE");
else{
System.out.println("RECTANGLE");
shape.centerPoint();
class Rectangle{
System.out.print("# ");
else{
System.out.print(" ");
System.out.println();
Polymorphism Quiz
by CodeChum Admin
import java.util.Scanner;
class Main{
Shape shape;
System.out.print("Shape(R/S/C): ");
case 'R':
System.out.print("Length: ");
System.out.print("Width: ");
System.out.println();
System.out.println();
break;
case 'S':
System.out.print("Side: ");
System.out.println();
System.out.println();
break;
case 'C':
System.out.print("Radius: ");
System.out.println();
System.out.println();
break;
interface Shape{
this.length = length;
this.width = width;
this.side = side;
this.radius = radius;
Interface Quiz
by CodeChum Admin
1. Create an interface Employee which has the attribute: rate, and the method getSalary().
2. Implement the Employee interface with two classes: Hourly and Commissioned.
3. Hourly employee has the following additional attribute: hoursWorked. Hourly wage is
300 money.
4. Commissioned employee has the following additional attribute: itemSold. Commissioned
employees get 200 money per item sold. If item sold is greater than 100, any items sold
after 100 has +10 money bonus.
import java.util.*;
interface Employee{
}
class Hourly implements Employee{
this.hours = hours;
this.itemSold = itemSold;
Employee person;
System.out.print("Enter type of employee: ");
switch(type){
case 'H':
break;
case 'C':
break;
Exceptions Quiz
by CodeChum Admin
Write a program that accepts an integer N which serves as the size of an array. Ask for N number
of elements. After, continuously ask for user input index. Mark the element at that index as zero.
If the user gives an invalid index, throw the appropriate exception and print "Illegal index!".
The program ends once an exception is thrown or once the array contains only zeroes. Lastly,
print the array elements separated by space.
import java.util.Scanner;
pro.input();
class SecMain{
System.out.print("Enter N: ");
System.exit(0);
}else{
proc(num);
array[a] = scan.nextInt();
try{
while(true){
array[total] = 0;
ctr++;
if(ctr == num){
break;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Illegal index!");
}finally{