[Link]
in/
Index
Q .no. Questions Page no. Remark
1 Write a program that implement the concept of Encapsulation. 03-04
Write a program to demonstrate the concept of function overloading of
2
Polymorphism.
05-06
Write a program to demonstrate concept of construction overloading of
3
Polymorphism.
07-08
Write a program the use Boolean data type and print the prime number
4
series up to 50.
09
Write a program to print first 10 number of the following Series
5
using Do-while Loops 0,1,1,2,3,5,8,11..
10
6 Write a program to check the given number is Armstrong or not 11-12
7 Write a program to find the factorial of any given number. 13
Write a program to sort the element of One Dimensional Array in
8 14
Ascending order
9 Write a program for matrix multiplication using input/output Stream. 15-16
10 Write a program for matrix addition using input/output Stream. 17-18
11 Write a program for matrix transpose using input/output stream class. 19-20
Write a program to add the element of Vectors as arguments of main
12
method(Run time ) and rearrange them, and copy it into an array.
21-22
13 Write a program to check that the given String is palindrome or not. 23-24
14 Write a program to arrange the String in alphabetical order. 25-26
Write a program for StringBuffer class which perform the all methods
15 27-28
of that class.
16 Write a program to calculate Simple interest using the Wrapper class. 29
Write a program to calculate Area of various geometrical figures using
17 30-31
the abstract class.
Write a program where Single class implements more than one
18 interfaces and with help of interface reference variable user call the 32-33
methods.
WAP that use the multiple catch statements within the try-catch
19
mechanism.
34
WAP where user will create a self- Exception using the “throw”
20 35
keyword.
Write a program for multithread using is Alive(), join() and
21
synchronized() methods of thread class
36-37
Write a program to create a package using command and one package
22
will import another package.
38-39
Write a program for JDBC to insert the values into the existing table by
23 40-41
using prepared statement.
WAP for JDBC to display the records from the existing table.
24 42-43
25 WAP for demonstrate of switch statement ,continue and break. 44-45
1
[Link]
Q1) Write a program that implement the concept of Encapsulation.
Ans :-
// Java program to demonstrate encapsulation
class Encapsulate {
// private variables declared
// these can only be accessed by public methods of class
private String Name;
private int Roll;
private int Age;
// get methods for age, name and roll
//to access private variables
public int getAge() { return Age; }
public String getName() { return Name; }
public int getRoll() { return Roll; }
// set methods for age, name and roll
//to access private variable Age
public void setAge(int newAge) { Age = newAge; }
public void setName(String newName) { Name = newName; }
public void setRoll(int newRoll) { Roll = newRoll; }
}
public class TestEncapsulation {
public static void main(String[] args)
{ Encapsulate obj = new Encapsulate();
// setting values of the variables
[Link]("manish");
[Link](21);
[Link](5527);
// Displaying values of the variables
[Link]("Student's name: " +
[Link]());
[Link]("Student's age: " + [Link]());
[Link]("Student's roll: " +
[Link]());
// Direct access of Roll is not possible
// due to encapsulation
// [Link]("Student's roll: " + [Link]);
}
}
Output :-
2
[Link]
Figure 1
3
[Link]
Q2) Write a program to demonstrate the concept of function overloading
of Polymorphism.
Ans :-
// Java program to demonstrate concept of function overloading of
Polymorphism
class Adder{
//Method Overloading: changing no. of arguments
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
//Method Overloading: changing data type of arguments
static double add(double a, double b){return a+b;}
static String add(String a, String b)
{String str = "Four"; return str; }
//Method Overloading: Sequence of data type of arguments
static void disp(String c, int num)
{[Link](c +" "+ num);}
static void disp(int num, String c)
{[Link](num +" "+ c);}
}
class TestOverloading{
public static void main(String[] args){
//Method Overloading: changing no. of arguments
[Link]([Link](11,11));
[Link]([Link](11,11,11));
//Method Overloading: changing data type of arguments
[Link]([Link](12.3,12.6));
[Link]([Link]("One","Three"));
//Method Overloading: Sequence of data type of
arguments [Link]("manish",5527);
[Link](9399,"hello");
}
}
4
[Link]
Output:
5
[Link]
Q3) Write a program to demonstrate concept of construction
overloading of Polymorphism.
Ans :-
// Java program to illustrate Constructor Overloading
class Box
{ double width, height, depth;
// constructor used when all dimensions specified
Box(double w, double h, double d)
{ width = w; height = h; depth = d; }
// constructor used when no dimensions specified Box()
{width = height = depth = 0;}
// constructor used when cube is created
Box(double len){width = height = depth = len;}
// compute and return volume
double volume() {return width * height * depth;}
}
public class Test
{ public static void main(String args[])
{ // create boxes using the various constructors
Box mybox1 = new Box(12, 21, 13);
Box mybox2 = new Box();
Box mycube = new Box(7);
double vol;
// get volume of first box
vol = [Link]();
[Link](" Volume of mybox1 is " + vol);
// get volume of second box
vol = [Link]();
[Link](" Volume of mybox2 is " + vol);
// get volume of cube
vol = [Link]();
[Link](" Volume of mycube is " + vol);
}
}
6
[Link]
Output:-
7
[Link]
Q4) Write a program the use Boolean data type and print the prime
number series up to 50.
Ans :-
// Java program to print the prime number series up to 50
public class PrimeNumber
{
public static void main(String []args)
{
int num=50,i;
[Link]("\n Prime numbers upto 50 :\n");
for(i=2;i<=num;i++)
{
boolean a=true;
for(int j=2;j<=i-1;j++)
{
if(i%j==0)
{ a=false;
break;
}
}
if(a==true)
{ [Link](" "+i);
}
}
[Link]();
}
}
Output:-
8
[Link]
Q5) Write a program to print first 10 number of the following Series
using Do-while Loops 0,1,1,2,3,5,8,11.
Ans :-
// Java program to print the Fibonacci number series up to 50
public class Fibonacci
{
public static void main(String []args)
{
// Function to print N Fibonacci Number
int N=10,b=-1,c=1,sum,i=1;
do
{
sum=b+c;
[Link](" "+sum);
// Swap
b=c;
c=sum;
i++;
}
// Iterate till i is N
while(i<=N);
[Link]();
}
}
Output:-
9
https://
Q6) Write a program to check the given number is Armstrong or not.
Ans :-
// Java program to find Nth Armstrong Number
import [Link];
public class Armstrong
{
public static void main(String []args)
{ int n,sum=0,count=0;
Scanner input= new Scanner([Link]); [Link]("\
nEnter a number to check Armstrong or not : ");
int number =[Link]();
int num=number;
// Find total digits in num
while(num!=0)
{ num=num/10;
count++;
}
//Copy the value for number in num
num=number;
// Calculate sum of power of digits
while (num != 0)
{ n=num%10; sum=sum+
(int)[Link](n,count);
num=num/10;
}
if (number == sum )
[Link]("\n"+number + " is an Armstrong
number ");
else
[Link]("\n"+number + " is not an
Armstrong number ");
}
}
1
https://
Output:-
1
https://
Q7) Writea program to find the factorial of any given number.
Ans :-
// Java program to find factorial of given number
import [Link];
class Test
{
// Method to find factorial of given number
static int factorial(int n)
{
int res = 1, i;
for (i=2; i<=n; i++)
res *= i;
return res;
}
// Driver method
public static void main(String[] args)
{
Scanner input=new Scanner([Link]); [Link]("\
nEnter a number to find factorial : "); int
num=[Link]();
[Link]("Factorial of "+ num + " is " +
factorial(num));
}
}
Output:-
1
https://
Q8) Write a program to sort the element of One Dimensional Array in
Ascending order
Ans :-
// Java Program to Sort Array of Integers using [Link]() Method
import [Link];
import [Link];
public class ArraySort{
public static void main(String args[]){
int []arr = new int[7];
Scanner enter = new Scanner([Link]);
[Link]("\nPlease! Enter 7 numbers to perform
sorting:");
for(int i=0; i<[Link]; i++)
{
arr[i]=[Link]();
}
// Applying sort() method over to above array
// by passing the array as an argument
[Link](arr);
[Link]("\nSorting in Ascending order :\n");
for(int i=0;i<[Link];i++)
{
[Link](" "+arr[i]);
}
[Link]( );
}
}
Output:-
1
https://
Q9) Write a program for matrix multiplication using input/output Stream.
Ans :-
// Java Program for matrix multiplication using input/output Stream
import [Link];
public class MatrixMultiplication{
public static void main(String []args)
{
Scanner input=new Scanner([Link]);
[Link]("Enter number of rows : ");
int r=[Link]();
[Link]("Enter number of columns : ");
int c=[Link]();
if(r!=c)
{
[Link]("\nSorry! matrix multiplication cannot
be performed..!");
[Link](0);
}
else
{ int m1[][]=new int[r][c];
int m2[][]=new int[r][c];
int m3[][]=new int[r][c];
int sum;
[Link]("Enter the elements of First
matrix row wise: ");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{ m1[i][j]=[Link]();
}
}
[Link]("Enter the elements of second
matrix row wise: ");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{ m2[i][j]=[Link]();
}
}
for(int i=0;i<r;i++)
{
1
https://
for(int j=0;j<c;j++)
{ sum=0;
for(int k=0;k<r;k++)
{ sum=sum + m1[i][k]*m2[k][j];
}
m3[i][j]=sum;
}
[Link]("Product of two matrices : ");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
[Link](" "+ m3[i][j]);
}
[Link]();
}
[Link]();
}
}
}
Output:-
1
https://
Q10) Write a program for matrix addition using input/output Stream.
Ans :-
// Java Program for matrix addition using input/output Stream
import [Link];
public class MatrixAddition{
public static void main(String []args)
{
Scanner input=new Scanner([Link]);
[Link]("Enter number of rows : ");
int r=[Link]();
[Link]("Enter number of columns : ");
int c=[Link]();
int m1[][]=new int[r][c];
int m2[][]=new int[r][c];
int m3[][]=new int[r][c];
[Link]("Enter the elements of First matrix
row wise:");
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
m1[i][j]=[Link]();
}
}
[Link]("Enter the elements of second matrix
row wise:");
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
m2[i][j]=[Link]();
}
}
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
m3[i][j]=m1[i][j]+m2[i][j];
}
}
[Link]("Sum of two matrices : ");
1
https://
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
[Link](" " +m3[i][j]);
}
[Link]();
}
[Link]();
}
}
Output: -
1
https://
Q11) write a program for matrix transpose using input/output stream
class.
Ans :-
// Java Program for matrix transpose using input/output stream class.
import [Link];
public class MatrixTranspose{
public static void main(String[] args)
{ Scanner input = new
Scanner([Link]); int original[][]=new
int[3][3] ;
[Link]("Enter the elements of matrix: ");
for(int row = 0; row<3; row++)
{
for(int col = 0; col<3; col++)
{ original[row][col] = [Link]();
}
}
int transpose[ ][ ] = new int[3][3];
for(int row = 0; row<3; row++)
{
for(int col = 0; col<3; col++)
{
transpose[row][col] = original[col][row];
}
}
[Link]("Transpose of matrix : \n");
for(int row = 0; row<3; row++)
{ for(int col = 0; col<3; col++)
{
[Link](" "+ transpose[row][col] );
}
[Link]("\n");
}
}
}
1
https://
Output:-
1
https://
Q12) Write a program to add the element of Vectors as arguments of main
method(Run time ) and rearrange them, and copy it into an array.
Ans :-
// Java Program to Demonstrate Working of Vector via Creating and
Using It
// Importing required classes
import [Link].*;
import [Link].*;
class VectorExample{
public static void main(String[] args)
{ // Size of the Vector
int n = 5;
Scanner input = new Scanner([Link]);
// Declaring the Vector with initial size n
Vector<Integer> list = new Vector<Integer>(n);
// Appending new elements at the end of the vector
try{ for(int i=0;i<5;i++)
[Link]([Link](args[i]));
// Printing elements of list [Link]("\
n"+list);
// Remove element at index 3
[Link](3);
//Displaying the vector after deletion
[Link](list);
// iterating over vector elements usign for loop
[Link]("Printing the list using [Link]() --
---");
for (int i = 0; i<[Link](); i++)
// Printing elements one by one
[Link](" "+[Link](i));
// Creating the array and using toArray()
Object[] arr = [Link]();
[Link]("\nPrinting the list using Array() ---
--");
for (int i = 0; i<[Link]; i++)
[Link](" "+arr[i]);
[Link]();
2
https://
}
catch(Exception e)
{ [Link]("\nProgram ended...............");
[Link]("Exception : "+[Link]());
}
}
}
Output:-
2
https://
Q13) write a program to check that the given String is palindrome or not.
Ans :-
// Java Program to check that the given String is palindrome or not.
import [Link];
public class Palindrome{
// Function that returns true if str is a palindrome
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning and the end of the string
int i = 0, j = [Link]() - 1;
// While there are characters to compare
while (i < j)
{
// If there is a mismatch
if ([Link](i) != [Link](j))
return false;
// Increment first pointer and decrement the other
i++; j--;
}
// Given string is a palindrome
return true;
}
public static void main(String[] args)
{
Scanner input= new Scanner([Link]);
[Link]("\nEnter a string to check : ");
String str=[Link]();
if (isPalindrome(str))
[Link](str + " is a palindrome.");
else
[Link](str + " is not a
palindrome.");
}
}
2
https://
Output:-
2
https://
Q14) write a program to arrange the String in alphabetical order.
Ans :-
// Java Program to arrange the String in alphabetical order
import [Link];
public class StringArrange{
public static void main(String[] args)
{ int count;
String temp;
Scanner scan = new Scanner([Link]);
//User will be asked to enter the count of strings
[Link]("\nEnter number of strings you
would like to enter:");
count = [Link]();
String str[] = new String[count];
Scanner scan2 = new Scanner([Link]);
//User is entering the strings and they are stored
in an array
[Link]("Enter the Strings one by one:");
for(int i = 0; i < count; i++)
{
str[i] = [Link]();
}
[Link]();
[Link]();
//Sorting the strings
for (int i = 0; i < count; i++)
{
for (int j = i + 1; j < count; j++)
{
if (str[i].compareTo(str[j])>0)
{ temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
//Displaying the strings after sorting them based on
alphabetical order
[Link]("\nStrings in Sorted Order : ");
2
https://
for (int i = 0; i <= count - 1; i++)
{
[Link](str[i] + ", ");
}
[Link]();
}
}
Output:-
2
https://
Q15) write a program for StringBuffer class which perform the all methods
of that class.
Ans :-
// Java Program for StringBuffer class which perform the all methods
of that class
import [Link].*;
public class StringBufferExample{
public static void main(String args[]){
//initialized StringBuffer object
StringBuffer sb = new StringBuffer("Good
Morning...");
[Link]("\n"+sb);
//append to String1
[Link](" Hello!!");
//prints "Good Morning... Hello!!" after appending
[Link](sb);
//insert Namste!! with begining position 0
[Link](0,"Namste!! ");
//prints "Namste!! Good Morning... Hello!!"
[Link](sb);
// replace Morning with Evening
[Link](13,20," Evening");
//prints "Namste!! Good Morning... Hello!!"
[Link](sb);
//delete string begining with position 0 to 3
[Link](0,8);
//prints "Good Morning... Hello!!"
[Link](sb);
//StringBuffer reverse() Method
[Link]();
[Link](sb);
//prints capacity of buffer
[Link]("capacity of buffer is: " +
[Link]());
}
}
2
https://
Output:-
2
https://
Q16) write a program to calculate Simple interest using the Wrapper class.
Ans :-
// Java Program to calculate Simple interest using the Wrapper class.
import [Link];
class SimpleInterest{
public static void main(String args[])
{ int principleAmount, rate, time
,si;
Scanner input = new Scanner([Link]);
[Link]("\nEnter principle amount : ");
String p = [Link]();
[Link]("Enter rate : ");
String r = [Link]();
[Link]("Enter time : ");
String t = [Link]();
principleAmount = [Link](p);
rate = [Link](r);
time = [Link](t);
si = (principleAmount * rate * time )/100;
[Link]("Simple Interest is : " + si );
}
}
Output:-
2
https://
Q17) write a program to calculate Area of various geometrical figures
using the abstract class.
Ans :-
// Java Program to calculate Simple interest using the Wrapper class.
import [Link].*;
//abstract class
abstract class Shape{
//abstract method declaration, Abstract method (does not
have a body)
abstract public void areaCalcultion();
abstract public void readData();
}
class Rectangle extends
Shape{ private int a,b;
//method overriding
public void readData(){
[Link]("\n\nEnter two sides of Rectangle : ");
Scanner sidein = new Scanner([Link]);
a = [Link]();
b = [Link]();
}
public void areaCalcultion(){
int area;
area = a * b;
[Link]("Area of Rectangle is : " + area);
[Link]("\n<--------------------------------------------->");
}
}
class Circle extends
Shape{ private double
radius;
//method overriding
public void readData(){
[Link]("\nEnter Radius of circle : ");
Scanner radiusin = new Scanner([Link]);
radius= [Link]();
}
public void areaCalcultion(){
double area = (22/7) * radius * radius;
[Link]("Area of circle is : " + area);
}
}
2
https://
public class AbstractArea{
public static void main(String args[]){
//Reference variable of Shape
Shape s;
s= new Rectangle(); // Creating object of abstract class
[Link]();
[Link]();
s=new Circle(); // Creating object of abstract class
[Link]();
[Link]();
}
}
Output:-
3
https://
Q18) write a program where Single class implements more than one
interfaces and with help of interface reference variable user call the
methods.
Ans :-
// Java Program to calculate Simple interest using the Wrapper class.
import [Link].*;
//interface
interface CircleArea{
final static float pi = 3.14F;
float compute(float x); //interface method
}
interface RectangleArea{
int calculate(int l,int w); //interface method
}
//Test implements interface CirclArea and RectangleArea
class Test implements CircleArea,RectangleArea
{ //the body of compute provided here
public float compute(float x) { return(pi*x*x); }
//the body of calculate provided here
public int calculate(int l,int w) { return(l*w); }
}
class Interface{
public static void main(String args[])
{ CircleArea cir;
RectangleArea rect;
//Creates a Test object
Test Area = new Test();
cir = Area;
[Link]("\nArea of circle : "+
[Link](49));
rect = Area;
[Link]("Area of Rectangle : " +
[Link](5,20));
}
}
3
https://
Output:-
3
https://
Q19) write a program that use the multiple catch statements within the try-
catch mechanism.
Ans :-
//Java Program for Multiple Catch Exceptions
public class MultipleCatch {
public static void main(String[] args) {
try
{ int a[]=new int[5];
a[5]=30/0;
}
//Arithmetic Exception occurs
catch(ArithmeticException e)
{
[Link]("\nArithmetic Exception
occurs");
}
//Array Index Out Of Bounds Exception occurs
catch(ArrayIndexOutOfBoundsException e)
{
[Link]("ArrayIndexOutOfBounds Exception
occurs");
}
//Other Exception occurs
catch(Exception e)
{
[Link]("Parent Exception occurs");
}
[Link]("rest of the code");
}
}
Output:-
3
https://
Q20) write a program where user will create a self- Exception using the
“throw” keyword.
Ans :-
//Java Program for user will create a self- Exception using the
“throw” keyword
import [Link];
class Throw{
public static void main(String args[])
{ int balance=5000;
int withdrawlAmount=6000;
try
{ if(balance< withdrawlAmount)
{ throw new
ArithmeticException("Insufficient balance");
}
balance=balance-withdrawlAmount;
[Link]("Transaction successfully
completed");
}
catch(ArithmeticException e)
{ [Link]("\nException: "+ [Link]());
}
finally
{ [Link]("Program continue...........");
}
}
}
Output:-
3
https://
Q21) write a program for multithread using is Alive(), join() and
synchronized() methods of thread class
Ans :-
//Java Program for multithread using is Alive(), join() and
// synchronized() methods of thread class
class Booking
{ int total_seats=20;
//Synchronized function
synchronized void bookseat(int seats)
{
if(total_seats>=seats)
{ [Link]("\nSeat Book Successfull...!!");
total_seats=total_seats-seats;
[Link]("Total seat Left : "+total_seats);
}
else
{ [Link]("\nSeat cannot be Booked");
[Link]("Only "+total_seats + "
available");
}
}
}
//Extending thread class
class cutomer extends Thread
{
static Booking b1=new Booking();
int seat;
public void run()
{
try
{ [Link](seat);
}
catch(NullPointerException e)
{ [Link]();
}
}
}
public class Synchro
{ public static void main(String[] args)
3
https://
{
cutomer C1=new cutomer();
cutomer C2=new cutomer();
[Link]=19;
[Link]=8;
[Link]();
[Link]();
//isAlive() method
[Link]([Link]());
try
{
//Thread sleep() and join method
[Link](2000);
[Link]();
}
catch (Exception e)
{
[Link]("Exception : "+[Link]());
}
}
}
Output:-
3
https://
Q22) write a program to create a package using command and one package
will import another package.
Ans :-
//Java Program to create a package using command
// Save by [Link] and
//compile as > javac –d . [Link]
package Pack1; //Creating package
import [Link];
public class ArithmeticOperations
{ private Scanner input = new Scanner([Link]);
public int Addition(){
int a = [Link]();
int b = [Link]();
return a+b;
}
public int Subtract(){
int a = [Link]();
int b = [Link]();
return a-b;
}
public int Multiplication(){
int a = [Link]();
int b = [Link]();
return a*b;
}
public float Division(){
float a = [Link]();
float b = [Link]();
return a/b;
}
}
3
https://
//Main class and method
//Save by [Link]
import [Link]; //Importing Pack1.
ArithmeticOperations class
class ExamplePackage
{ public static void main(String args[])
{ ArithmeticOperations obj = new ArithmeticOperations();
[Link]("\nAddition : Enter Two Number - ");
float result = [Link]();
[Link]("Result is :"+result);
[Link]("\nSubtraction : Enter Two Number - ");
result = [Link]();
[Link]("Result is :"+ result);
[Link]("\nMultiplication : Enter Two Number -
");
result = [Link]();
[Link]("Result is :"+result);
[Link]("\nDivision : Enter Two Number - ");
result = [Link]();
[Link]("Result is :"+result);
}
}
Output:-
3
https://
Q23) write a program for JDBC to insert the values into the existing table
by using prepared statement.
Ans :-
//Java Program to insert the values into the existing table by using
prepared statement.
import [Link].*;
import [Link].*;
import [Link].*;
public class Database{
public static void main(String args[])
{ int roll;
String name,city, str;
try{ //step1 load the driver class
[Link]("[Link]");
//step2 create the connection object
Connection con =
[Link]("jdbc:oracle:thin:@localhost:
1521:xe","bhupendra","dbms@12"); [Link]("\
nDatabase connection is done !");
//step3 create the statement object
Statement stmt = [Link]();
//step4 execute query
[Link]("\n<---STUDENT table is selected ---
>");
InputStreamReader input= new InputStreamReader([Link]);
BufferedReader buffer = new BufferedReader(input);
[Link]("\nEnter rollno : " );
str = [Link]();
roll = [Link](str);
[Link]("Enter name : " );
name = [Link]();
3
https://
[Link]("Enter Address : " );
city = [Link]();
int count = [Link]("Insert into Students
values("+roll+",'"+name+"','"+city+"')");
if (count>0)
[Link]("\n<-----Data inserted
successfully-------->\n");
else
[Link]("Data insertion failed!!!!!!!");
//step5 close the connection object
[Link]();
}
catch(Exception e)
{
[Link](e);
}
}
}
Output:-
4
https://
Q24) write a program for JDBC to display the records from the existing
table.
Ans :-
//Java Program for JDBC to display the records from the existing
table.
import [Link].*;
import [Link].*;
public class OracleCon{
public static void main(String args[])
{ String sname,city;
int id;
try{
//step1 load the driver class
[Link]("[Link]");
//step2 create the connection object
Connection con =
[Link]("jdbc:oracle:thin:@localhost:
1521:xe","bhupendra","dbms@12"); [Link]("\
nDatabase connection done");
//step3 create the statement object
Statement stmt = [Link]();
//step4 execute query
ResultSet rs = [Link]("select * from
Students");
while([Link]())
{ id = [Link]("S_ID");
sname = [Link]("S_NAME");
city = [Link]("S_ADDRESS");
[Link]("\t|"+id+"\t| "+sname+" \t| "+city+"\
t|");
}
//step5 close the connection object
[Link]();
}
4
https://
catch(Exception e)
{ [Link]("Exception occur : ");
[Link](e);
}
}
}
Output:-
4
https://
Q25) write a program for demonstrate of switch statement ,continue and
break.
Ans :-
//Java Program to demonstrate the example of Switch statement
import [Link].*;
public class SwitchExample {
public static void main(String[] args) {
Scanner input=new Scanner([Link]);
[Link]("\nEnter number of day :");
int Day = [Link]();
switch (Day) {
case 7:
[Link]("Today is Sunday");
break;
case 1:
[Link]("Today is Monday");
break;
case 2:
[Link]("Today is Tuesday");
break;
case 3:
[Link]("Today is Wednesday");
break;
case 4:
[Link]("Today is Thursday");
break;
case 5:
[Link]("Today is Friday");
break;
case 6:
[Link]("Today is Saturday");
break;
}
[Link]("\n<<------------------------------->>\n");
[Link]("Java program to demonstrates the
continue");
for (int i = 0; i < 10; i++)
{ // If the number is 2 skip and continue
if (i == 2)
continue;
[Link](i + " ");
4
https://
}
[Link]();
}
}
Output:-