0% found this document useful (0 votes)
29 views

Java Lab

The document discusses object oriented programming concepts like checking even-odd numbers, positive-negative numbers, leap years, loops, methods, classes, objects, inheritance, polymorphism, exception handling and more with examples. Code snippets and outputs are provided for different programs to demonstrate various OOP concepts.

Uploaded by

Saheli Bakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Java Lab

The document discusses object oriented programming concepts like checking even-odd numbers, positive-negative numbers, leap years, loops, methods, classes, objects, inheritance, polymorphism, exception handling and more with examples. Code snippets and outputs are provided for different programs to demonstrate various OOP concepts.

Uploaded by

Saheli Bakshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

Object Oriented Programming

Saheli Bakshi
KINGSTON SCHOOL OF MANAGEMENT & SCIENCE
Kingston School of Management & Science (College Code: 173)
Object Oriented Programming (BCAC 301)

Name: Saheli Bakshi


Roll Number: 17301220045
Reg. No: 201731001210004

Index:
SL Title Date
No.
1. Even or Odd 06/09/2021
2. Positive or negative, Leap year or not 13/09/2021
3. Loop (while, for), Reverse Number, 15/09/2021
Palindrome Number
4. Do-while loop, short circuit operator 16/09/2021
5. Class object, Odd even checking with 20/09/2021
Method
6. Checking Prime number using Method 21/09/2021
7. Method Overloading 22/09/2021
8. Typecasting 23/09/2021
9. Constructor, checking Prime No with 27/09/2021
Class & Constructor
10. Constructor Overloading 28/09/2021
11. Array 29/09/2021
12. Binary search, Linear search, Matrix 30/09/2021
(addition, multiplication, transpose)
13. Irregular array, sparce matrix, 04/10/2021
Inheritance
14. Abstract Method Overriding 05/10/2021
15. Access Specification 07/10/2021
16. String 01/11/2021
17. String as Immutable class 02/11/2021
18. Reverse an immutable String, Exception 08/11/2021
Handling
19. Compile time exception 09/11/2021
20. Throws Keyword 10/11/2021
21. Thread 11/11/2021
22. Multithreading 22/11/2021
23. Applet 25/11/2021
24. Package 07/12/2021

P a g e 1 | 58
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.

P a g e 2 | 58
1. Checking Even Odd

Code:

import java.util.*;
class Test
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int x=sc.nextInt();
if(x%2==0)
System.out.println(x + " is even number");
else
System.out.println(x + " is odd number");
}
}

Output:

P a g e 3 | 58
2. Positive or Negative Number

Code:

import java.util.*;
class PositiveNegative
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers: ");
int x=sc.nextInt();
int y=sc.nextInt();
if(x>=0 && y>=0)
System.out.println("Both the numbers are positive");
else if(x<0 && y<0)
System.out.println("Both the numbers are negative");
else
System.out.println("One number is positive another is negative");
}

Output

P a g e 4 | 58
Leap Year

Code:

import java.util.*;
class LeapYear
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a year: ");
int y=sc.nextInt();
if((y%4==0 && y%100!=0) || (y%400==0))
System.out.println("It is a Leap Year");
else
System.out.println("It is NOT a Leap Year");
}
}

Output:

P a g e 5 | 58
Using while loop

Code:

import java.util.*;
class WhileLoop
{
public static void main(String args[])
{
//Scanner sc=new Scanner(System.in);
//System.out.println("Enter a number: ");
//int i=sc.nextInt();
int i=1;
while(i<=10)
{
System.out.println("i="+i);
i++;
}
}
}

Output:

P a g e 6 | 58
Using for loop

Code:

import java.util.*;
class ForLoop
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int i=sc.nextInt();
for(;i<=10;i++)
{
System.out.println("For i="+i);
}
}

Output:

P a g e 7 | 58
Reverse Number

Code:

import java.util.*;
class ReverseNumber
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int n=sc.nextInt();
System.out.print("Reverse number: ");
while(n>0)
{
System.out.print(n%10);
n=n/10;
}
}

Output:

P a g e 8 | 58
Palindrome Number

Code:

import java.util.*;
class PalindromeNumber
{
public static void main(String args[])
{
int r,rev=0,n1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int n=sc.nextInt();
n1=n;
while(n>0)
{
r=n%10;
rev=rev*10 +r;
n=n/10;
}
System.out.print("Reverse number: "+rev);
if(rev==n1)
System.out.print("\n\nNumber is palindrome");
else
System.out.print("\n\nNumber is NOT palindrome");
}
}

Output:

P a g e 9 | 58
Do While Loop

Code

import java.util.*;
class DoWhileLoop
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int n=sc.nextInt();
do //Exit controlled loop
{
System.out.println("Number "+n);
n--;
}while(n>0);
}
}

Output:

P a g e 10 | 58
Short Circuit operator

Code:

class Test

public static void main(String args[])

int x=5,y=10;

System.out.println(x++>10 && y++>100);

System.out.println(y);

Output:

P a g e 11 | 58
Code:

class Test1

public static void main(String args[])

int x=5,y=10;

System.out.println(x++>0 || y++>100);

System.out.println(y);

Output:

P a g e 12 | 58
Class & Object

Code:

class TestObject
{
int x;
void meth()
{
System.out.println("1st Object program...");
System.out.println("Value of x="+x);
}
}

class TestMyOblect
{
public static void main(String ghhgtd[])
{
TestObject to=new TestObject();
to.x=5;
to.meth();
}
}

Output:

P a g e 13 | 58
Check even odd with class & object

Code:

import java.util.Scanner;

class Test {

int n, i, p = 1;

Scanner sc = new Scanner(System.in);

void input() {

System.out.print("Enter a number:");
n = sc.nextInt();
}

void check() {

if (n % 2 == 0) {
System.out.println("Number is even:" + n);
} else {
System.out.println("Number is odd:" + n);
}

}
}

class Main {

public static void main(String args[]) {

Test obj = new Test();


obj.input();
obj.check();

}
}

P a g e 14 | 58
Output:

P a g e 15 | 58
Check prime number

Code:

import java.util.*;
class TestPrime1
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number:");
int n=sc.nextInt();
CheckPrime1 cp=new CheckPrime1();
int val=cp.isPrime(n);
if(val==0)
{
System.out.println("Number is not prime");
}
else
{
System.out.println("Number is prime");
}
}
}

class CheckPrime1
{
int isPrime(int x)
{
for(int i=2;i<=x/2;i++)
{
if(x%i==0)
return 0;
}
return 1;
}

Output

P a g e 16 | 58
P a g e 17 | 58
Static polymorphism \ Method Overloading

Code:

class MethodOverloading
{
public void disp(char c, int num)
{
System.out.println("Hey, This is Saheli Bakshi.");
}
public void disp(int num, char c)
{
System.out.println(" I am a student of BCA." );
}
}
class SaheliBakshi
{
public static void main(String args[])
{
MethodOverloading obj = new MethodOverloading();
obj.disp('x', 33 );
obj.disp(21, 'y');
}
}

Output:

P a g e 18 | 58
Implicit Typecasting

Code:

class Typecasting{
public static void main(String[] args) {
// create int type variable
int num = 10;
System.out.println("The integer value: " + num);

// convert into double type


double data = num;
System.out.println("The double value: " + data);
}
}

Output:

P a g e 19 | 58
Explicit Typecasting

Code:

class MainType {
public static void main(String[] args) {
// create double type variable
double num = 10.99;
System.out.println("The double value: " + num);

// convert into int type


int data = (int)num;
System.out.println("The integer value: " + data);
}
}
Output:

P a g e 20 | 58
Constructor

Code

class TestConstr

TestConstr()

System.out.print("1st Constractor program......");

} }

class MyCons

{ public static void main(String hg[])

TestConstr tc=new TestConstr();

Output:

P a g e 21 | 58
Check prime number with Constructor

Code

class TestConstr {

TestConstr(int x) {

int count=0;

for(int i=2;i<=x/2;i++) {

if(x%i==0) count++;

if(count==0)

{ System.out.println(x+" is Prime number..."); }

else { System.out.println(x+"is NOT a Prime number...");

} } }

class MyConstructor {

public static void main(String hg[]) {

TestConstr tc=new TestConstr(50);

} }

Output:

P a g e 22 | 58
Constructor Overloading

Code

public class Student {


//instance variables of the class
int id;
String name;

Student(){
System.out.println("this a default constructor");
}

Student(int i, String n){


id = i;
name = n;
}

public static void main(String[] args) {


//object creation
Student s = new Student();
System.out.println("\nDefault Constructor values: \n");
System.out.println("Student Id : "+s.id + "\nStudent Name : "+s.name);

System.out.println("\nParameterized Constructor values: \n");


Student student = new Student(10, "David");
System.out.println("Student Id : "+student.id + "\nStudent Name :
"+student.name);
}
}
Output:

P a g e 23 | 58
Array

Code

class TestArray
{
public static void main(String args[])
{
int arr[]=new int[5]; //static
System.out.println("Enter array elements:");
for(int i=0;i<5;i++)
{
arr[i]=i;
}
System.out.println("Array elements:");
for(int i=0;i<5;i++)
{
System.out.println(arr[i]);
}
}
}

Output:

P a g e 24 | 58
Linear Search

Code

import java.util.*;
class TestArray3
{
public static void main(String args[])
{
System.out.println("Enter how many array elements you want?");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();

int arr[]=new int[n]; //Dynamic


System.out.println("Enter array elements:");
for(int i=0;i<arr.length;i++)
{
arr[i]=sc.nextInt();
}

System.out.print("\nEnter which element you want to search:");


int s=sc.nextInt();
int c=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]==s)
{
c++;
System.out.print("\nItem present in array at position "+(i+1));
break;
P a g e 25 | 58
}
}
if(c==0)
{
System.out.print("\nItem Not present...");
}

}
}
Output:

Binary Search
class BinarySearchExample
{
public static void binarySearch(int arr[], int first, int last, int key){
int mid = (first + last)/2;
while( first <= last ){
if ( arr[mid] < key ){
first = mid + 1;
}else if ( arr[mid] == key ){
System.out.println("Element is found at index: " + mid);
break;
}else{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last ){
System.out.println("Element is not found!");
}
P a g e 26 | 58
}
public static void main(String args[]){
int arr[] = {10,20,30,40,50};
int key = 30;
int last=arr.length-1;
binarySearch(arr,0,last,key);
}
}

Output:

P a g e 27 | 58
Matrix

Code

import java.util.*;
class TestTwoArray
{
public static void main(String args[])
{
System.out.println("Enter how many row and column you want?");
Scanner sc=new Scanner(System.in);
int row=sc.nextInt();
int col=sc.nextInt();
int arr[][]=new int[row][col]; //Dynamic two-D Array
System.out.println("Enter array elements:");

for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("\nArray elements:");
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
System.out.print(arr[i][j] + " ");
}
System.out.println();
P a g e 28 | 58
}
}
}

Output:

Matrix addition

Code

import java.util.*;
class TestTwoArray1
{
public static void main(String args[])
{
System.out.println("Enter how many row and column you want?");
Scanner sc=new Scanner(System.in);
int row=sc.nextInt();
int col=sc.nextInt();
int arr1[][]=new int[row][col]; //Dynamic two-D Array
int arr2[][]=new int[row][col];
int arr3[][]=new int[row][col];
System.out.println("Enter " +(row*col)+" array elements in the 1st
Matrix:");
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr1[i][j]=sc.nextInt();
}
}

System.out.println("Enter " +(row*col)+" array elements in the 2nd


Matrix:");
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
P a g e 29 | 58
{
arr2[i][j]=sc.nextInt();
}
}

for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr3[i][j]=arr1[i][j]+arr2[i][j];
}
}

System.out.println("\nAddition of two array:");


for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
System.out.print(arr3[i][j] + " ");
}
System.out.println();
}
}
}

Output:

P a g e 30 | 58
matrix multiplication

Code

public class MatrixMultiplicationExample{  
public static void main(String args[]){  
//creating two matrices    
int a[][]={{1,1,1},{2,2,2},{3,3,3}};    
int b[][]={{1,1,1},{2,2,2},{3,3,3}};    
    
//creating another matrix to store the multiplication of two matrices    
int c[][]=new int[3][3];  //3 rows and 3 columns  
    
//multiplying and printing multiplication of 2 matrices    
for(int i=0;i<3;i++){    
for(int j=0;j<3;j++){    
c[i][j]=0;      
for(int k=0;k<3;k++)      
{      
c[i][j]+=a[i][k]*b[k][j];      
}//end of k loop  
System.out.print(c[i][j]+" ");  //printing matrix element  
P a g e 31 | 58
}//end of j loop  
System.out.println();//new line    
}    
}}  

P a g e 32 | 58
matrix transpose

Code

public class MatrixTransposeExample{  
public static void main(String args[]){  
//creating a matrix  
int original[][]={{1,3,4},{2,4,3},{3,4,5}};    
    
//creating another matrix to store transpose of a matrix  
int transpose[][]=new int[3][3];  //3 rows and 3 columns  
    //Code to transpose a matrix  
for(int i=0;i<3;i++){    
for(int j=0;j<3;j++){    
transpose[i][j]=original[j][i];  
}    
}    
  
System.out.println("Printing Matrix without transpose:");  
for(int i=0;i<3;i++){    
for(int j=0;j<3;j++){    
System.out.print(original[i][j]+" ");    
}    
System.out.println();//new line    
}    
P a g e 33 | 58
System.out.println("Printing Matrix After Transpose:");  
for(int i=0;i<3;i++){    
for(int j=0;j<3;j++){    
System.out.print(transpose[i][j]+" ");    
}    
System.out.println();//new line    
}    
}}  

P a g e 34 | 58
Irregular Array

Code

import java.util.*;
class TestIrrArr
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int arr[][]=new int[3][]; //irregular array

arr[0]=new int[2];
arr[1]=new int[3];

System.out.println("Enter 2 elements:");
for(int i=0;i<2;i++)
arr[0][i]=sc.nextInt();

System.out.println("Enter 3 elements:");
for(int i=0;i<3;i++)
arr[1][i]=sc.nextInt();

System.out.println("2 elements:");
for(int i=0;i<2;i++)
System.out.print(arr[0][i] + " ");
System.out.println("\n 3 elements");
for(int i=0;i<3;i++)
System.out.print(arr[1][i]+" ");
}
}

Output:

P a g e 35 | 58
Inheritance

Code

class Aa
{
int x;
void meth()
{
System.out.print("\nFrom Parent class...");
}
}
class Bb extends Aa
{
void meth1()
{
System.out.print("\nFrom Child class");
}
}
class TestInherit
{
public static void main(String khg[])
{
Bb b=new Bb();
b.x=5;
b.meth();
b.meth1();
System.out.print("\nValue of x="+b.x);

P a g e 36 | 58
}
}

Output:

P a g e 37 | 58
Abstract Method Overriding

Code

abstract class ParentClass


{
int x;
void meth()
{
System.out.print("\nFrom Parent class...");
}

abstract void methAbs(); //Abstract Method


}

class ChildClass extends ParentClass


{
void meth1()
{
System.out.print("\nFrom Child class");
}

void methAbs() //Abstract method overriding


{
System.out.print("\nAbstract method of parent overriden......");

P a g e 38 | 58
}

class TestMyInherit
{
public static void main(String khg[])
{
ChildClass b=new ChildClass();
b.x=5;
b.meth();
b.meth1();
b.methAbs();
System.out.print("\nValue of x="+b.x);
}
}

P a g e 39 | 58
P a g e 40 | 58
Access Specification

Code

class TestPrivate
{
private int x=5;
public int y=7;

int returnPrivate()
{
return x;
}
}

class MyTestPrivate
{
public static void main(String kjg[])
{
TestPrivate tp=new TestPrivate();
System.out.println("Public data Y="+ tp.y);

//System.out.println("X="+ tp.x); //Error

System.out.println("Private data X="+tp.returnPrivate());


}
}

Output:

P a g e 41 | 58
String

Code

class TestString
{
public static void main(String khg[])
{
String s1=new String("ABCDE");
System.out.println("1st String:"+s1);

String s2="FGH";
System.out.println("2nd String:"+s2);

System.out.println("Length of 1st String:"+ s1.length());

//System.out.println("1st String + 2nd String ="+ s1.concat(s2));

s1=s1.concat(s2);

System.out.println("1st String:"+s1);

System.out.println("Length of 1st String:"+ s1.length());

System.out.println("Character at position:"+ s1.charAt(4));

System.out.println("Sub-String:"+ s1.substring(3,5));

String s3=s1.toLowerCase();

System.out.println(s3);

P a g e 42 | 58
P a g e 43 | 58
String as immutable class

Code

// class is declared final


final class Immutable {
// private class members
private String name;
private int date;
Immutable(String name, int date) {
// class members are initialized using constructor
this.name = name;
this.date = date;
}

// getter method returns the copy of class members


public String getName() {
return name;
}
public int getDate() {
return date;
}
}
class Maintain {
public static void main(String[] args) {
// create object of Immutable
Immutable obj = new Immutable("Programiz", 2011);

System.out.println("Name: " + obj.getName());


System.out.println("Date: " + obj.getDate());
}
}

P a g e 44 | 58
P a g e 45 | 58
Reverse string

Code

class StringReverse
{
public static void main(String bakshi[])
{
String s1="Te Amo";
String s2="";
for(int i=s1.length()-1 ;i>=0; i--)
{
s2=s2 + s1.charAt(i);
}
System.out.println("Reverse of String:" + s2);
}
}

Output:

P a g e 46 | 58
Exception Handling

Code

//Example of Compile time exception


import java.io.*;
class ExceptionHandling
{
public static void main(String khg[])
{
try{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader bfr=new BufferedReader(isr);

System.out.println("Enter 1st number: ");


int a=Integer.parseInt(bfr.readLine());

System.out.println("Enter 2nd number: ");


int b=Integer.parseInt(bfr.readLine());

int c=a/b;
System.out.println("C="+c);
}
catch(Exception e)
{
System.out.println("Exception solved by BCA students : "+ e);
}
finally
{
System.out.println("In Finally.... \nEnd of Code....");
}
}
}
Output:

P a g e 47 | 58
Throws Keyword

Code

//Example of throws keyword

import java.io.*;

class TestException2

{ public static void main(String khg[])

throws Exception

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader bfr=new BufferedReader(isr);

System.out.println("Enter 1st number: ");

int a=Integer.parseInt(bfr.readLine());

System.out.println("Enter 2nd number: ");

int b=Integer.parseInt(bfr.readLine());

int c=a/b; System.out.println("C="+c);

} }

P a g e 48 | 58
Multithreading

Code

class Count implements Runnable


{
Thread mythread ;
Count()
{
mythread = new Thread(this, "my runnable thread");
System.out.println("my thread created" + mythread);
mythread.start();
}
public void run()
{
try
{
for (int i=0 ;i<10;i++)
{
System.out.println("Printing the count " + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("my thread interrupted");
}
System.out.println("mythread run is over" );
}
}
class RunnableExample
{
public static void main(String args[])
{
Count cnt = new Count();
try
{
while(cnt.mythread.isAlive())
{
System.out.println("Main thread will be alive till the child thread is live");
Thread.sleep(1500);
}
}
catch(InterruptedException e)
{
System.out.println("Main thread interrupted");
}
System.out.println("Main thread run is over" );
}
P a g e 49 | 58
}

P a g e 50 | 58
Thread with in-built method

Code

//thread.yield method

class ThreadBCA1 implements Runnable


{
public void run()
{
try{
for(int i=1;i<=20;i++)
{
System.out.println("1st Thread Running...");
Thread.yield();
}
}
catch(Exception e){}
}
}

class ThreadBCA2 implements Runnable


{
public void run()
{
try{
for(int i=1;i<=20;i++)
{
System.out.println("2nd Thread Running...");
Thread.yield();
}
}
catch(Exception e){}
}
}

class ThreadBCA3 implements Runnable


{
public void run()
{
for(int i=1;i<=20;i++)
{
System.out.println("3rd Thread Running...");
}
}
}

class MyMainThread1

P a g e 51 | 58
public static void main(String jhf[])

throws Exception

{ ThreadBCA1 tb1=new ThreadBCA1();

Thread th1=new Thread(tb1);

ThreadBCA2 tb2=new ThreadBCA2();

Thread th2=new Thread(tb2);

ThreadBCA3 tb3=new ThreadBCA3();

Thread th3=new Thread(tb3);

th1.start();

th1.join();

th2.start();

th2.join();

th3.start();

th3.join();

System.out.println("\nMain thread ends............");

} }

P a g e 52 | 58
Code

//thread.sleep method
class ThreadBCA1 implements Runnable
{
public void run()
{
try{
for(int i=1;i<=20;i++)
{
System.out.println("1st Thread Running...");
Thread.sleep(1000);
}
}
catch(Exception e){}
}
}

P a g e 53 | 58
Applet
Developing an Applet Program

Steps to develop an applet program


1. Create an applet (java) code i.e. .java file.
2. Compile to generate .class file.
3. Design a HTML file with <APPLET> tag.

Running the Applet Program

There are two ways to run the applet program


1. By HTML
2. Appletviewer tool

code

import java.awt.*;
import java.applet.*;
public class AppletDemo
{
      public void paint(Graphics g)
      {
           g.drawString("Welcome to TutorialRide", 50, 50);
      }
}

1. Save the above program: AppletDemo.java


2. Compile: > javac AppletDemo.java

//AppletDemo.html

<html>
      <head>
            <title> AppletDemo </title>
      </head>

P a g e 54 | 58
      <body>
            <applet code="AppletDemo.class" width="200"
height="250">
            </applet>
      </body>
</html>

Run the complete program:


> appletviewer AppletDemo.html

NOTE: To execute the applet program through appletviewer tool,


write it on command prompt.
C :\> javac AppletDemo.java
C :\> appletviewer AppletDemo.java

P a g e 55 | 58
Package
Step 1: Create a folder with name "ArithmeticOperation"
Step 2: within that folder create classes as:

Code

package ArithmeticOperation;
public class Sum
{
private int x,y;
public Sum(int a,int b)
{
X=a;
y=b;
}
public long add()
{
return(x+y);
}
}

package ArithmeticOperation;
public class Substract
{
private int a,b;
public Substract(int x,int y)
{
a=x; b=y;
}
public long substraction()
{
return(a-b);
}
}

Step 3: Create another class just outside the folder "ArithmeticOperation" that contains the main
method as:

import java.io.*;
import ArithmeticOperation.*;
class Operation
{
public static void main(String sr[])
{
try
{
P a g e 56 | 58
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(isr);
System.out.println("Enter two Integer: ");
int templ=Integer.parselnt(br.readLine();
int temp2=Integer.parselnt(br.readLine();
Sum s=new Sum(templ,temp2);
Substract st= new Substract(temp1,temp2);
System.out.println("Addition=" +s.add());
System.out.println("Substraction= "+st.substraction));
}
Catch(exception e)
{
System.out.println(e);
}
}
}

P a g e 57 | 58

You might also like