You are on page 1of 4

Java Practical Exercise

1. Write a program to print odd number series and even number series based on the user given
number.

2. Write a program to check whether the given number is positive, negative or zero.

3. Write a program to find the greatest number in three given numbers.

4. Write a program to find out the second greatest number in three given numbers.

5. Calculate the sum of two numbers which are not greatest in three given numbers.

6. Print a Floyd's triangle of star.

*
**
***

7. Print a Pascal triangle of star.

*
* *
* * *

8. If cost price and selling price of an item is input through the keyboard, write a program to
determine whether the seller has made profit or incurred loss. Also determine how much profit he
made or loss he incurred.

9. Write a program to check whether a triangle is valid or not, when the three angles of the triangle
are entered through the keyboard.

10. Given the length and breadth of a rectangle, write a program to find whether the area of the
rectangle is greater than its perimeter.

11. Write a program to check whether the given year is leap year or not.

12. A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10
days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days
your membership will be cancelled. Write a program to accept the number of days the member is
late to return the book and display the fine or the appropriate message.

13. If the three sides of a triangle are entered through the keyboard, write a program to check whether
the triangle is valid or not. The triangle is valid if the sum of two sides is greater than the largest
of the three sides.

14. Print the numbers 1 - 10 in reverse order.


15. Accept any number from 1 - 10 and print the numbers from 1 - 10 other than the user given
number.(using ‘continue’)

16. Write a program to swap two number using temporary variable.

17. Write a program to swap two number without using temporary variable.

18. Write a program to check whether the given number is prime or not.

19. Write a program to print the Fibonacci series of 'n' user given no.of elements.

20. Write a program to find out the reverse of the given number. (153 --> 351)

21. Write a program to find out the given number is the palindrome or not.(4334)

22. Consider the following number 45*45=2025; 20+25=45.Write a program to generate number
between 32 and 99 that satisfies the above property.

23. Write a C program to find a two digit number, the second digit of which is smaller than its first
digit by 4, and if the number was divided by the digit’s sum, the quotient would be 7.

24. Write a program to calculate overtime pay of 3 employees. Overtime is paid at the rate of Rs.
12.00 per hour for every hour worked above 40 hours.

25. Write a program to find the factorial value of any number entered through the keyboard.

26. Two numbers are entered through the keyboard. Write a program to find the value of one number
raised to the power of another.

27. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each
digit of the number is equal to the number itself, then the number is called an Armstrong number.
For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

28. Write a program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and
continue)

29. Write a program to print the multiplication table of the number entered by the user. The table
should get displayed in the following form.

29 * 1 = 29

29 * 2 = 58

30. Write a program to enter the numbers till the user wants and at the end it should display the count
of positive, negative and zeros entered.

31. Write a program to generate all combinations of 1, 2 and 3 using for loop.

32. Print a numeric pyramid.


33. Write a program to find out the sum of the array.

34. Write a program to find the greatest and the smallest element of the given array.

35. Write a program to sort the array elements.

36. Write a program to check whether the given array elements are in Arithmetic Progression or not.

37. Write a program to swap two 1D arrays.

38. Write a program to find out the sum of diagonal elements of the given 2D array.

39. Write a program to search for the given element in an array.

40. Write a program to multiply a user given number with the given matrix.

41. Write a program to do a matrix multiplication.

42. Write a program to print the transpose of the given matrix.

43. Write a program to find out the factorial for the user given number.(5!=5x4x3x2x1 i.e 5!=5x4!)

44. Write a menu driven program for addition, subtraction, multiplication and division of two given
numbers using function. The main() should have function calls only.

45. Write a program to accept the student name and three marks from the user and calculate the total,
average and grade using functions.

46. Write a program to check whether the given number is an Amstrong number or not.

47. 153 =>No.of its digits is 3 => 1^3 + 5^3 + 3^3 = 1+125+27 = 153(same as the given number)

48. Write a program to find out the given number is an Adam number or not.

49. 12  square(12)=144  reverse(144)=441 square root(441)=21reverse(21)=12(same as the


given number)

Strings

50. Write a program to welcome the user if their username and the password are of same size.

51. Write a program to welcome the user if their username and the password are same.

52. Write a program to welcome the user until they give the same username and the password.

53. Write a program to ask for the username and give them the same username as the password. Then
ask them to check for the login by asking username and password. If they are valid give a
welcome note. If not throw an error message.

54. Write a program to ask for the Student No and the Dept name and the password. Password should
be in the format of Student No@Dept(Eg: 101@ece). If it is valid give a welcome note. If not ask
them whether they wish to try again or not. If they wish provide the needs. If not terminate the
program after saying an end note.

55. Write a program to check whether the given string is a palindrom or not.(Eg: Madam)

56. Write a program that converts a string like "124" to an integer 124.

57. Write a program to check whether the given character is present in a given string or not.

58. Write a program to print every word of the string "Welcome to KGiSL" in new line.

59. Write a program to the find out number of capital letters, small letters, spaces and special
characters in a given string.

60. Write a program to convert a uppercase string into lowercase and lowercase string into uppercase.

61. Create the base class student_info with following fields rollNo, name, dob, gender, also write the
functions for getting and displaying the data and create sub class with following fields
mark1,mark2,mark2,total,avg also write the functions for getting data, calculate the total & avg
and displaying the data

62. Print the numbers in sequence using interface. Declare the following methods in interface.

int getNext(), void reset(); void start();

63. Write the program to get the student marks information, raise the arithmetic exception manually
when will the enter student marks is greater than 100.

64. Write a program to check a person is eligible for vote or not using user define exception.

65. Write a code for store the student information in database using JDBC.

66. Write a program get the student marks and calculate total and average using swing and event.

67. Write a program get the student marks & calculate total and average and store that information in
database using swing, event &JDBC.

You might also like