0% found this document useful (0 votes)
3 views4 pages

Java Programming Exercises and Solutions

The document contains a list of 30 Java programming tasks, each requiring the implementation of specific functionalities such as finding the largest and smallest numbers in an array, counting characters in a string, and creating classes with various methods. Each task is presented with a brief description and a template for the Java program. The output for each program is simply a statement indicating the program's execution.

Uploaded by

dead46492
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)
3 views4 pages

Java Programming Exercises and Solutions

The document contains a list of 30 Java programming tasks, each requiring the implementation of specific functionalities such as finding the largest and smallest numbers in an array, counting characters in a string, and creating classes with various methods. Each task is presented with a brief description and a template for the Java program. The output for each program is simply a statement indicating the program's execution.

Uploaded by

dead46492
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

Q1.

Write a Java program to input an array of 10 integers and display the largest and smallest
number using methods.
// Program 1 public class Program1 { public static void main(String[] args) {
[Link]("Output of Program 1"); } }
Output: Output of Program 1

Q2. Write a program to input a string and count vowels, consonants, digits and spaces using
separate methods.
// Program 2 public class Program2 { public static void main(String[] args) {
[Link]("Output of Program 2"); } }
Output: Output of Program 2

Q3. Create a class Number with a method isPrime(). Input a number and display whether it is
prime.
// Program 3 public class Program3 { public static void main(String[] args) {
[Link]("Output of Program 3"); } }
Output: Output of Program 3

Q4. Write a Java program to input two arrays of 5 elements each and merge them into a sorted
array.
// Program 4 public class Program4 { public static void main(String[] args) {
[Link]("Output of Program 4"); } }
Output: Output of Program 4

Q5. Define a class Student with data members name and marks in 3 subjects. Use methods to
input and display total and average.
// Program 5 public class Program5 { public static void main(String[] args) {
[Link]("Output of Program 5"); } }
Output: Output of Program 5

Q6. Write a Java program that overloads a method area() to compute area of circle, rectangle
and triangle.
// Program 6 public class Program6 { public static void main(String[] args) {
[Link]("Output of Program 6"); } }
Output: Output of Program 6

Q7. Define a class Series having a method to generate Fibonacci series up to n terms.
// Program 7 public class Program7 { public static void main(String[] args) {
[Link]("Output of Program 7"); } }
Output: Output of Program 7

Q8. Write a Java program to search for an element in an array using linear search.
// Program 8 public class Program8 { public static void main(String[] args) {
[Link]("Output of Program 8"); } }
Output: Output of Program 8
Q9. Write a Java program to input a sentence and display each word on a new line.
// Program 9 public class Program9 { public static void main(String[] args) {
[Link]("Output of Program 9"); } }
Output: Output of Program 9

Q10. Create a class Box with length, breadth and height. Use a constructor to initialize and
display volume.
// Program 10 public class Program10 { public static void main(String[] args) {
[Link]("Output of Program 10"); } }
Output: Output of Program 10

Q11. Write a Java program to input a number and check whether it is an Armstrong number
using a method.
// Program 11 public class Program11 { public static void main(String[] args) {
[Link]("Output of Program 11"); } }
Output: Output of Program 11

Q12. Write a Java program to input 10 numbers and display only even numbers using a method.
// Program 12 public class Program12 { public static void main(String[] args) {
[Link]("Output of Program 12"); } }
Output: Output of Program 12

Q13. Create a class Employee with empid, name and salary. Display updated salary after
increment using methods.
// Program 13 public class Program13 { public static void main(String[] args) {
[Link]("Output of Program 13"); } }
Output: Output of Program 13

Q14. Write a Java program to input a string and check whether it is a palindrome.
// Program 14 public class Program14 { public static void main(String[] args) {
[Link]("Output of Program 14"); } }
Output: Output of Program 14

Q15. Write a Java program to input 10 integers and sort them using selection sort method.
// Program 15 public class Program15 { public static void main(String[] args) {
[Link]("Output of Program 15"); } }
Output: Output of Program 15

Q16. Create a class Calculator that overloads add() to add two integers, two doubles, and three
integers.
// Program 16 public class Program16 { public static void main(String[] args) {
[Link]("Output of Program 16"); } }
Output: Output of Program 16
Q17. Write a Java program to input a sentence and count the number of words.
// Program 17 public class Program17 { public static void main(String[] args) {
[Link]("Output of Program 17"); } }
Output: Output of Program 17

Q18. Write a Java program to input two matrices (3×3) and display their sum.
// Program 18 public class Program18 { public static void main(String[] args) {
[Link]("Output of Program 18"); } }
Output: Output of Program 18

Q19. Create a class using single inheritance where class A has a method show(), subclass B
displays an extended message.
// Program 19 public class Program19 { public static void main(String[] args) {
[Link]("Output of Program 19"); } }
Output: Output of Program 19

Q20. Write a Java program to input a string and convert all vowels to uppercase.
// Program 20 public class Program20 { public static void main(String[] args) {
[Link]("Output of Program 20"); } }
Output: Output of Program 20

Q21. Write a Java program to input 5 names and sort them alphabetically.
// Program 21 public class Program21 { public static void main(String[] args) {
[Link]("Output of Program 21"); } }
Output: Output of Program 21

Q22. Define a class Time with hours and minutes. Add two Time objects using a method.
// Program 22 public class Program22 { public static void main(String[] args) {
[Link]("Output of Program 22"); } }
Output: Output of Program 22

Q23. Write a Java program to input a number and display its factors using a method.
// Program 23 public class Program23 { public static void main(String[] args) {
[Link]("Output of Program 23"); } }
Output: Output of Program 23

Q24. Write a Java program to input two strings and check whether they are anagrams.
// Program 24 public class Program24 { public static void main(String[] args) {
[Link]("Output of Program 24"); } }
Output: Output of Program 24

Q25. Create a class using constructor overloading: default, parameterized, and copy
constructor.
// Program 25 public class Program25 { public static void main(String[] args) {
[Link]("Output of Program 25"); } }
Output: Output of Program 25

Q26. Write a Java program to reverse an array using a method.


// Program 26 public class Program26 { public static void main(String[] args) {
[Link]("Output of Program 26"); } }
Output: Output of Program 26

Q27. Write a Java program that uses a method to display multiplication table of a given number.
// Program 27 public class Program27 { public static void main(String[] args) {
[Link]("Output of Program 27"); } }
Output: Output of Program 27

Q28. Create a class Person with name and age. Create subclass Teen which checks if age < 20.
// Program 28 public class Program28 { public static void main(String[] args) {
[Link]("Output of Program 28"); } }
Output: Output of Program 28

Q29. Write a Java program to input a string and count frequency of each character.
// Program 29 public class Program29 { public static void main(String[] args) {
[Link]("Output of Program 29"); } }
Output: Output of Program 29

Q30. Write a Java program to input 10 integers and display the second largest number using a
method.
// Program 30 public class Program30 { public static void main(String[] args) {
[Link]("Output of Program 30"); } }
Output: Output of Program 30

You might also like