• No results found

Data Structures through Java Lab Manual-Part-I

N/A
N/A
Protected

Academic year: 2020

Share "Data Structures through Java Lab Manual-Part-I"

Copied!
24
0
0

Loading.... (view fulltext now)

Full text

(1)

1 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Data Structures through Java Lab Manual

Program1: Java Program to find out the given number is prime or not.

Aim: To write a java program to find whether the given number is prime or not.

Definitions:

Prime: A number is said to a prime number if it is divisible by 1 and itself only. In other words, a

number having only two divisors is called as a prime number.

Example: 2, 5, 7 and so on.

Program: // Prime.java

class Prime {

public static void main(String[] args) {

int n,count=0; n=23;

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

if(n%i==0) {

count++; }

}

if(count==0) {

System.out.println("The number " + n + " is Prime"); }

else {

System.out.println("The number " + n + " is not a Prime"); }

(2)

2 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Output:

Program2: Java Program to find the sum and average of numbers using Command Line arguments.

Aim: To write a java program to find the sum and average of numbers using Command Line arguments. Definitions:

Command Line arguments:

Command line represents the run command and the values given at the time of running the program. Command line arguments represents the values passed to main() method.

To catch and store these values, main() has a parameter, String args[] as public static void main(String args[])

Here, args[] is a one dimensional array os string type. So it can store a group of strings, passed to main() from command prompt by the user at the time of running the program.

Program: // CommandLine.java

class CommandLine {

public static void main(String[] args) {

int n,len,sum=0; float avg; len=args.length; for(int i=0;i<len;i++) {

n=Integer.parseInt(args[i]); sum=sum+n;

}

avg=sum/len;

System.out.println("The Sum=" + sum); System.out.println("The avearge=" + avg); }

(3)

3 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Output:

Program 3: Java Program to find the sum of two numbers, it has to use two classes. Aim: To write a java program to find the sum of two numbers using the concept of two classes. Definitions:

Class: “A class is a way of binding the data and associated methods in a single unit”. Any Java program

if we want to develop then that should be developed with respective to class only i.e., without class there is no Java program.

Syntax for creating a class:

class <class_name> {

Data Members of the class; Member functions of the class; }

Object: Objects are the basic runtime entities in an object-oriented system. In order to store the data for

the data members of the class, we must create an object.

Syntax for creating the Object:

1. <class_name> <object_name>=new <class_name>(); 2. <class_name> <object_name>; //Declaring a class variable

<object_name> = new <class_name>(); // Initializing the class variable.

Program: //AdditionDemo.java

class Addition {

int a,b,c;

void getData(int x,int y) {

a=x; b=y; }

void sum() {

c=a+b; }

(4)

4 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram System.out.println("The first number is:" + a);

System.out.println("The second number is:" + b); System.out.println("The sum is: " + c);

} }

class AdditionDemo {

public static void main(String[] args) {

int a,b; a=10; b=20;

Addition a1=new Addition(); a1.getData(a,b);

a1.sum(); a1.putData(); }

}

Output:

Program 4: Java Program to find whether the given number is an ArmStrong number or not using an interactive input

Aim: To write a Java program to find out whether the given number is ArmStrong or not using an

interactive input.

Definitions:

readLine() method: readLine() is a method used to read the string data from the keyboard. It is there in

the DataInputStream class. Therefore, if we want to call the readLine() method in our program we need to use the object of DataInputStream class. Each time the readLine() method throws an exception called IOException.

parseInt() method: It is a method used to convert the string data into an integer value and it is a static

method in Integer class. So we can call this method by using the following sysntax. Integer_variable=Integer.parseInt(Stringvalue);

ArmStrong: If the sum of the cubes of the individual digits of the given number is equal to that number

(5)

5 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Example: 153 ( 13 + 53 + 33 = 1 + 125 + 27 =153).

Program: //ArmStrong.java

import java.io.*; class ArmStrong {

int n,m,sum,rem; void getData(int x) {

n=x; m=x; }

void findArmStrong() {

sum=0;

while(n>0) {

rem=n%10;

sum=sum+(rem*rem*rem); n=n/10;

} }

void putData() {

if(sum==m) {

System.out.println("\n The given number " + m + " is an ArmStrong number"); }

else {

System.out.println("\n The given number " + m + " is not an ArmStrong number"); }

}

public static void main(String[] args) throws IOException {

int n;

DataInputStream dr=new DataInputStream(System.in); ArmStrong a1=new ArmStrong();

(6)

6 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram a1.findArmStrong();

a1.putData(); }

}

Output:

Program 5: Java Program to demonstrate the concept of Method Overloading Aim: To write a Java program to demonstrates the concept of Method Overloading. Definitions:

Method Overloading: In Java, it is possible to create methods that have the same name, but different

signature. This is called Method Overloading. Here, signature represents Return type of the method.

Number of arguments in the method. Type of arguments in the method. Order of arguments in the method.

Method Overloading = Method name is same + Signature is different.

Method overloading is used when objects are required to perform similar tasks but using different input parameters.

Program: //MethodOverload.java

class MethodOverload {

int sum(int a,int b) {

return a+b; }

float sum(float a,float b) {

(7)

7 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram double sum(double a, double b)

{

return a+b; }

int sum(char a,char b) {

return a+b; }

public static void main(String[] args) {

MethodOverload m1=new MethodOverload();

System.out.println("The Integer sum is: " + m1.sum(10,20)); System.out.println("The Float sum is: " + m1.sum(12.5f,15.5f)); System.out.println("The Double sum is: " + m1.sum(10.9,20.5)); System.out.println("The Character sum is: " + m1.sum('A','B')); }

}

Output:

Program 6: Java Program to illustrate the concept of static member functions. Aim: To write a Java program that illustrates the concept of static member functions. Definitions:

static method

It is a method which belongs to the class and not to the object(instance)

A static method can access only static data. It cannot access non-static data (instance variables)

A static method can call only other static methods and cannot call a non-static method from it.

A static method can be accessed directly by the class name and doesn’t need any object

The following is the syntax for accessing a static variable

(8)

8 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Program: //StaticDemo.java

class MathOperation {

static float mul(float x, float y) {

return x*y; }

static float divide(float x, float y) {

return x/y; }

}

class StaticDemo {

public static void main(String[] args) {

//Calling the static methods using the class name

float mul=MathOperation.mul(5.0f,4.0f); float div=MathOperation.divide(5.0f,2.0f);

System.out.println("Multiplication=" + mul); System.out.println("Division=" + div); }

}

Output:

Program 7: Java Program to illustrate the concept of switch case and do-while control statements. Aim: To write a Java program that illustrates the use of switch case and do-while control statements. Definitions:

Branching or Selection

When a program breaks the sequential flow and jumps to another part of the code, it is called selection or branching.

(9)

9 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram If branching takes place without any condition, it is known as unconditional branching.

Definition of Loop:

The process of repeatedly executing a block of statements is known as looping. The statements in the block may be executed any number of times, from zero to infinite number of times. If a loop continues forever, it is called an infinite loop.

Program: // MenuDriven.java

import java.io.*; class MenuDriven {

public static void main(String[] args) throws IOException {

int a,b,c,ch;

DataInputStream dr=new DataInputStream(System.in); System.out.println("Enter two integer numbers....\n"); a=Integer.parseInt(dr.readLine());

b=Integer.parseInt(dr.readLine());

System.out.println("1. Addition"); System.out.println("2. Subtraction"); System.out.println("3. Multiplication"); System.out.println("4. Division");

System.out.println("5. Modulo Division"); System.out.println("6. Exit");

do {

System.out.println("Enter yoyr choice....\n"); ch=Integer.parseInt(dr.readLine());

switch(ch) {

case 1: c=a+b;

System.out.println("The sum is:" + c); break;

case 2: c=a-b;

System.out.println("The subtraction is:" + c); break;

case 3: c=a*b;

(10)

10 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram case 4: c=a/b;

System.out.println("The division is:" + c); break;

case 5: c=a%b;

System.out.println("The modulo is:" + c); break;

case 6: System.exit(0); }

}while(ch<6); }

}

Output:

Program 8: Java program to illustrate the concept of Single Level Inheritance Aim: To write a Java program that illustrates the concept of Single Level Inheritance. Definitions:

The process of obtaining the data members and member functions from one class to another class is known as Inheritance.

(11)

11 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

The class which is retrieving or obtaining the data members and member functions is known as derived/sub/child class.

A Derived class contains some of features of its own plus some of the data members from base class.

Single Level Inheritance:

It is one it contains a single base class and a single derived class. It is shown in below.

Program: // InheritTest.java

class Room {

int len,bre; Room(int x,int y) {

len=x; bre=y; }

int area() {

return len*bre; }

}

class BedRoom extends Room {

int hei;

BedRoom(int x,int y,int z) {

//calling super class constructor super(x,y);

(12)

12 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram int volume()

{

return len*bre*hei; }

}

class InheritTest {

public static void main(String[] args) {

BedRoom r1=new BedRoom(14,12,10); int area=r1.area();

int vol=r1.volume();

System.out.println("Area=" + area); System.out.println("Volume=" + vol); }

}

Output:

Program 9: Java program to illustrate the concept of Method Overriding Aim: To write a Java program that illustrates the concept of Method Overriding. Definitions:

Method Overriding:

The process of redefining the same method for many numbers of implementations is called as method overriding.

The method overriding is possible by defining a method in the sub class that has the same name, same arguments and same return type as a method in the super class.

Method Overriding = Method Heading is same + Method body is different.

super keyword:

(13)

13 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

To differentiate the base class data members with the derived class data members.

To call the super class constructor from its derived class constructor.

Program: // OverrideDemo.java

class BC {

int a,b;

BC(int a, int b) {

this.a=a; this.b=b; }

void op() {

int c=a+b;

System.out.println("I am from BC"); System.out.println("The sum=" + c); }

}

class DC extends BC {

DC(int x, int y) {

super(x,y); }

void op() {

int c=a*b;

System.out.println("I am from DC");

System.out.println("The Multiplication=" + c); }

}

class OverrideDemo {

public static void main(String[] args) {

DC d1=new DC(100,200); d1.op();

(14)

14 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Output:

Program 10: Java program to sort the given strings in alphabetical order using the String class methods

Aim: To write a Java program to sort the strings in alphabetical order by using the String class methods. Definitions:

Strings

• A string is a sequence/group of characters.

• Strings in java are implemented as objects of the class “String” unlike other languages which implement strings using character arrays.

• Once a string (object) is created, we cannot change the characters in that string. Rather, we can create a new string object.

• All kind of string operations like concatenation, copying, case inversion and substring and many others can be performed on string objects.

Program: // StringOrder.java

class StringOrder {

public static void main(String[] args) {

String name[]={"Madras","Delhi","Ahmadabad","Calcutta","Bombay"}; String temp=null;

int len;

len=name.length;

System.out.println("\n The number of strings are...." + len); System.out.println("Strings before sorting are....");

for(int i=0;i<len;i++) {

System.out.println(" " + name[i]); }

(15)

15 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram for(int i=0;i<len;i++)

{

for(int j=1;j<len;j++) {

if(name[j].compareTo(name[i])<0) {

temp=name[i]; name[i]=name[j]; name[j]=temp; }

} }

System.out.println("Strings after sorting are....\n"); for(int i=0;i<len;i++)

{

System.out.println(" " + name[i]); }

}//main() }//class

Output:

Program 11: Java Program to illustrate the concept of the wrapper classes Aim: To write a Java program that illustrates the concept of wrapper classes in java. Definitions:

Wrapper class: Primitive data types may be converted into object types by using the wrapper classes

contained in the java.lang package.

(16)

16 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram import java.io.*;

class WrapperDemo {

static float loan(float p,float r, int t) {

return (p*t*r)/100; }

public static void main(String[] args) throws IOException {

Float principleAmount=new Float(0); // Converting number to object. Float intrestRate=new Float(0);

int numMonths=0;

DataInputStream dr=new DataInputStream(System.in); System.out.println("Enter Principle Amount:");

String principleString=dr.readLine();

//Converting String object to number object principleAmount=Float.valueOf(principleString); System.out.println("Enter Interest Rate:");

String intrestString=dr.readLine(); intrestRate=Float.valueOf(intrestString); System.out.println("Enter number of months:");

numMonths=Integer.parseInt(dr.readLine()); //Numeric string to number float value=loan(principleAmount.floatValue(),intrestRate.floatValue(),numMonths);

System.out.println("========================================"); System.out.println("Intrest Amount=" + value);

System.out.println("========================================"); }//main()

}//class

(17)

17 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram

Program 12: Java Program to illustrate the concept of Vector class in java Aim: To write a java program that illustrates the concept of Vector class in java. Vector:

Vector is a class contained in java.util package.

It is used to create a generic dynamic array known as vector that can hold objects of any type and any number.

The objects do not have to be homogeneous.

The vectors are created as follows

Vector vect=new Vector(); // declaring without size.

Vector list=new Vector(3);// declaring with size 3.

A Vector without size can accommodate an unknown number of items.

When a size is specified, this can be overlooked and a different number of items may be put into the vector.

Program:// VectorDemo.java

import java.util.*; class VectorDemo {

public static void main(String[] args) {

Vector v=new Vector();

v.addElement("C"); v.addElement("CPP"); v.addElement("JAVA"); v.addElement("Dot Net"); v.addElement("SAP");

v.insertElementAt("COBOL",2); int size=v.size();

String s[]=new String[size]; v.copyInto(s);

System.out.println("List of languages as string objects are"); for(int i=0;i<size;i++)

{

(18)

18 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram System.out.println("\n List of languages as a vector:" + v);

} }

Output:

Program 13: Java Program to implement the Multiple Inheritance using the Interfaces Aim: To write a java program to implement the multiple inheritance using the interfaces. Definitions:

Interface: An interface is a special case of abstract class, which contains all the final variables and

abstract methods (methods without their implementation).

Multiple Inheritance: It is one in which it contains multiple base classes and a single derived class. It is

not possible implement multiple inheritance through classes in java but it is possible through interfaces.

Program: //Hybrid.java

class Student {

int rno;

void getNumber(int n) {

rno=n; }

void putNumber() {

System.out.println("Roll No:" + rno); }

}

class Test extends Student {

(19)

19 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram void getMarks(float m1,float m2)

{

part1=m1; part2=m2; }

void putMarks() {

System.out.println(" Marks Obtained"); System.out.println("Part1=" + part1); System.out.println("Part2=" + part2); }

}

interface Sports {

float sportWt=6.0f; void putWt(); }

class Results extends Test implements Sports {

float total;

public void putWt() {

System.out.println("Sports Wt= " + sportWt); }

void display() {

total=part1+part2+sportWt; putNumber();

putMarks(); putWt();

System.out.println("Total score= " + total); }

}

class Hybrid {

public static void main(String args[]) {

(20)

20 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram }

}

Output:

Program 14: Java program to illustrate the concept of Thread Priorities in java Aim: To write a java program that illustrates the concept of Thread Priorities. Definitions:

Thread:

A flow of control is known as thread.

A Thread represents a separate path of execution of statements.

Thread Priority: In java, each thread is assigned a priority, which effects the order in which it is

scheduled for running. The Threads of the same priority are given equal treatment by the java scheduler and, therefore, they share the processor on a First-Come, First-Serve basis.

The Thread class defines several priority constants.

MIN_PRIOITY=1

NORM_PRIORITY=5

MAX_PRIORITY=10

Program:// ThreadPriority.java

class A extends Thread

{

public void run()

{

(21)

21 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram for(int i=1;i<=5;i++)

{

System.out.println("\t From Thread A : i= " + i);

}

System.out.println("Exit from Thread A");

}

}

class B extends Thread

{

public void run()

{

System.out.println("Thread B Started....");

for(int j=1;j<=5;j++)

{

System.out.println("\t From Thread B : j= " + j);

}

System.out.println("Exit from Thread B");

}

}

class C extends Thread

{

public void run()

{

System.out.println("Thread C Started....");

(22)

22 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram {

System.out.println("\t From Thread C : k= " + k);

}

System.out.println("Exit from Thread C");

}

}

class ThreadPriority

{

public static void main(String args[])

{

A threadA=new A();

B threadB=new B();

C threadC=new C();

threadC.setPriority(Thread.MAX_PRIORITY);

threadB.setPriority(threadA.getPriority()+1);

threadA.setPriority(Thread.MIN_PRIORITY);

System.out.println("Start Thread A");

threadA.start();

System.out.println("Start Thread B");

threadB.start();

System.out.println("Start Thread C");

threadC.start();

(23)

23 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram }

}

Output:

Program 15: Java program using the multiple catch blocks Aim: To write a java program that uses multiple catch blocks. Definitions:

Exception:

Run time errors in java are known as exceptions.

Run time errors are those which are coming in a program when the user inputs invalid data.

Exception Handling:

Exception handling is a mechanism of converting system error messages into user friendly messages.

Program:// ExceptionDemo.java class ExceptionDemo

{

(24)

24 Padmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::BhimavaramPadmasri Dr B V Raju Institute of Computer Education, Vishnupur::Bhimavaram {

int a[]={5,10}; int b=5; try {

int x=a[2]/(b-a[1]); }

catch(ArithmeticException e) {

System.out.println("Division by zero"); }

catch(ArrayIndexOutOfBoundsException e) {

System.out.println("Array Index Error"); }

catch(ArrayStoreException e) {

System.out.println("Wrong data type"); }

int y=a[1]/a[0];

System.out.println("y=" + y); }

}

References

Related documents

When dealing with the syntactic function, we shall address the main syntactic features of auxiliary verbs by reviewing (1) the ir main syntactic constructions; (2) the

If you use red for work activities, whenever you shade in an hour box with red, you’ll know that’s time you spent on work.. Blue may stand

Schedule No. c) The cost of Annual Comprehensive Maintenance Contract (CMC) which includes preventive maintenance, labour and spares, after satisfactory completion

Schedule No. c) The cost of Annual Comprehensive Maintenance Contract (CMC) which includes preventive maintenance, labour and spares, after satisfactory completion

b) The CMC commence from the date of expiry of all obligations under Warranty i.e. c) The cost of Annual Comprehensive Maintenance Contract (CMC) which includes

Please note, candidates for Epidemiology and Cancer Registry Certificate course and Certificate course in Cytotechnology need not appear for the Entrance Examination,

Schedule No. c) The cost of Annual Comprehensive Maintenance Contract (CMC) which includes preventive maintenance, labour and spares, after satisfactory completion

Schedule No. c) The cost of Annual Comprehensive Maintenance Contract (CMC) which includes preventive maintenance, labour and spares, after satisfactory completion