0% found this document useful (0 votes)
5 views44 pages

Saniya Javaprograms

The document outlines a series of Java programming tasks, including printing 'Hello World', using different data types, conditional statements, looping statements, arrays, static members, constructors, inheritance, method overriding, exceptions, and string classes. Each task specifies the requirement to write a program and includes placeholders for program code and output. The document serves as a comprehensive guide for practicing various Java programming concepts.

Uploaded by

saniyabanayeem39
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views44 pages

Saniya Javaprograms

The document outlines a series of Java programming tasks, including printing 'Hello World', using different data types, conditional statements, looping statements, arrays, static members, constructors, inheritance, method overriding, exceptions, and string classes. Each task specifies the requirement to write a program and includes placeholders for program code and output. The document serves as a comprehensive guide for practicing various Java programming concepts.

Uploaded by

saniyabanayeem39
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Q1.

Write a programin Java


to print Hello World
Program code:

Output:
Q.2 Write a program in Java
uses Different DataTypes
Program code:

Output:
Q.3 Conditional Statements
1. Write a program in java to check
whether the given number is even or
odd using conditional operator?

Program code:

Output:
2. Write a program in java to check
whether the given number is
positive or negative using if
statement

Program code:
Output:
3. Write a program in java to
check whether the given year is
leap or not using if statement
Program code:

Output:
4. Write a program in Java To
check maximum among three
numbers using nested if.

Program code:
Output:
5. Write a program in Java To
find the grades of student by
accepting marks of four
subjects using else if ladder
Program code:
Output:
6. Write a program in Java to
accept the month number and
display the name of month
using switch case
Program code:
Output:
Q.4 Looping Statement:
1. Write a program in Java to find
the factorial of given number by
using for loop

Program code:
Output:
3.WriteaprograminJavatodis
playsquarenumbersof1to5u
sing do whileloop.

Program code:

Output:
2. Write a program in Java to
display the numbers from 1 to
10 except 5 using while loop

Program code:

Output:
4.WAPinJavatodisplaythefollowing
output using nested forloop.
1
12
123
1234
Program code:

Output:
5.WriteaprograminJavatodisplaythe
following output using nested whileloop

1
22
333
4444

Program code:

Output:
6.WriteaprograminJavatodisplaythefollo
wingoutputusing nested do whileloop
1
23
456
78910
Program code:

Output:
Q5.Arrays.
1.WriteaprograminJava to
search an element in an array.

Program code:
Output:
2.Write a program in Java to
sort array in ascending order.

Program code:

Output:
3.Write a program in Java to
add two matrices of size 3X3.

Program code:
output:
Q6.Write a program in Java for
this keyword

Program code :

Output:
Q7.WriteaprograminJava for
Method Overloading

Program code:

Output:
Q8. Static members.
1. Write a program in Java for static
variable

Program code:

Output:
2. Write a program in Java for
static method.

Program code:

Output:
Q9. Constructor.
1. Write a program in Java for
default constructor

Program code:

Output:
2. Write a program in Java for
parameterized constructor

Program code :

Output:
Q10. Inheritance.
1. Write a program in Java for
single inheritance

Program code :

Output:
2. Write a program in Java for
multilevel inheritance

Program code:

Output:
3. Write a program in Java for
hierarchical inheritance

Program code :

Output:
Q11.Write a program in java for
method overriding

Program code:

Output:
Q12.Write a program in java for
demonstration of Final variable,
Method and Final Class

Program code:

Output:
Q13. Write a program in java
for demonstration of defining
and implementing interface.

Program code:

Output:
Q14. Write a program in java to
demonstrate creating and
accessing package

Program code:
Step1: create package-

Step2: Access the Package in


Another Java File-
k

Output:
Q15.Exception
1. Write a program in Java for
exception

Program code:

Output:
2. Write a program in Java for
multiple catch blocks

Program code :

Output:
3. Write a program in Java for
finally block

Program code:

Output:
Q16. String classes.
1. Write a program in Java to string
concatenate, convert string to upper case and
lower case, find substring, compare two
strings, find length of string using String class

Program code :

Output:
2. Write a program in Java to append
string, insert string, set length of string,
modify nth character in the string using
String Buffer class.

Program code :

Output:
19) Write a program in Java to
demonstrate reading from and
writing in to the files

Program code:

Output:

You might also like