Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
60 views

CSA09 Programming in Java Easy

The document contains 42 Java programming questions divided into different categories like Strings, Arrays, Patterns, General programs etc. Each question includes sample inputs, outputs and test cases. The questions cover basic to intermediate Java concepts like string manipulation, arrays, patterns, functions, conditionals, loops etc.

Uploaded by

Dain Mathew
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

CSA09 Programming in Java Easy

The document contains 42 Java programming questions divided into different categories like Strings, Arrays, Patterns, General programs etc. Each question includes sample inputs, outputs and test cases. The questions cover basic to intermediate Java concepts like string manipulation, arrays, patterns, functions, conditionals, loops etc.

Uploaded by

Dain Mathew
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

SAVEETHA SCHOOL OF ENGINEERING

SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL SCIENCES


INSTITUTE OF PLACEMENT AND TRAINING
CSA09 –JAVA PROGRAMMING
String

1. Write a program to reverse a word using loop? (Not to use inbuilt functions)
Sample Input:
String: TEMPLE
Sample Output:
Reverse String: ELPMET

2. Write a program to convent the given string to integer?


Sample Input:
String: 1234
Sample Output:
Out put String: 1234

3. Write a program to check the entered user name is valid or not. Get both the inputs from the
user.

4. Write a program that would sort a list of names in alphabetical order Ascending or
Descending, choice get from the user?
Sample Input:
Banana
Carrot
Radish
Apple
Jack
Order(A/D) : A
Sample Output:
Apple
Banana
Carrot
Jack
Radish

5. Write a program to print the special characters separately and print number of Special
characters in the line?

6. Write a program to print the number of vowels in the given statement?


Sample Input:
Saveetha School of Engineering
Sample Output:
Number o vowels = 12
7. Write a program to print consonants and vowels separately in the given word
Sample Input:
Given Word: Engineering
Sample Output:
Consonants: n g n r n g
Vowels: e i e ei

8. Write a program that finds whether a given character is present in a string or not. In case it is
present it prints the index at which it is present. Do not use built-in find functions to search
the character.
Sample Input:
Enter the string: I am a programmer
Enter the character to be searched: p
Sample Output:
P is found in string at index: 8
Note: Check for non available Character in the given statement as Hidden Test case.

9. Write a program to arrange the letters of the word alphabetically in reverse order
Sample Input:
Enter the word: MOSQUE
Sample Output:
Alphabetical Order: U S Q O M E
Test Case:
1. HYPOTHECATION
2. MATRICULATION
3. MANIPULATION

10. Write a program that accepts a string from user and displays the same string after removing
vowels from it.
Sample Input & Output:
Enter a string: we can play the game
The string without vowels is: w cn ply thgm

Arrays:

11. Write a program for matrix multiplication?


Sample Input:
Mat1 = 1 2
5 3
Mat2 = 2 3
4 1
Sample Output:
Mat Sum = 10 5
22 18
12. Write a program for matrix addition?
Sample Input:
Mat1 = 1 2
5 3
Mat2 = 2 3
4 1
Sample Output:
Mat Sum = 3 5
9 4
13. Write a program for Merge two sorted arrays using Array list
Input: arr1[] = { 1, 3, 4, 5}, arr2[] = {2, 4, 6, 8}
Output: arr3[] = {1, 2, 3, 4, 4, 5, 6, 8}

14. Find the Mean, Median, Mode of the array of numbers?


Sample Input;:
Array of elements = {16, 18, 27, 16, 23, 21, 19}
Sample Output:
Mean = 20
Median = 19
Mode = 16
Test cases:
1. Array of elements = {26, 28, 37, 26, 33, 31, 29}
2. Array of elements = {1.6, 1.8, 2.7, 1.6, 2.3, 2.1, .19}
3. Array of elements = {0, 160, 180, 270, 160, 230, 210, 190, 0}
4. Array of elements = {200, 180, 180, 270, 160, 270, 270, 190, 200}
5. Array of elements = {100, 100, 100, 100, 100, 100, 100, 100, 100}

15. Write a program to find the number of composite numbers in an array of elements
Sample Input;:
Array of elements = {16, 18, 27, 16, 23, 21, 19}
Sample Output:
Number of Composite Numbers = 5
Test cases:
1. Array of elements = {26, 28, 37, 26, 33, 31, 29}
2. Array of elements = {1.6, 1.8, 2.7, 1.6, 2.3, 2.1, .19}
3. Array of elements = {0, 160, 180, 270, 160, 230, 210, 190, 0}
4. Array of elements = {200, 180, 180, 270, 270, 270, 190, 200}
5. Array of elements = {100, 100, 100, 100, 100, 100, 100, 100}

Patterns :

16. Write a program to print Right Triangle Star Pattern


Sample Input:: n = 5
Output:
*
**
***
****
*****
17. Write a program to print the below pattern?
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

18. Write a program to print rectangle symbol pattern.


Get the symbol as input from user

19. Write a program to print the following pattern


Sample Input:
Enter the number to be printed: 1
Max Number of time printed: 3
1
11
111
11
1

20. Write a program to print the Inverted Full Pyramid pattern?

21. Write a program to print the following pattern


Sample Input:
Enter the Character to be printed: %
Max Number of time printed: 3
%
%%
%%%

22. Write a program to print hollow square symbol pattern?

23. Write a program to print the below pattern


1
2 2
3 3 3
4 4 4 4

24. Write a program to print the below pattern


1
4 9
16 25 36
49 64 81 100

25. Write a program to print the below pattern


1
22
3 3 3
4 4 4 4
3 3 3
2 2
1

26. Write a program to print hollow Square Dollar pattern?

27. Write a program to print inverted pyramid pattern.


Input: no of rows: 3
Output
*****
***
*
General:
28. Write a program to reverse a number using loop?(Get the input from user)
Sample Input:
Number: 14567
Sample Output:
Reverse Number: 76541
Test cases:
1. -45721
2. 000
3. AD1947
4. !@#$%
5. 145*999=144855

29. Write a program to convert the given decimal to binary and print the reverse of the binary
decimal.
Input: 11
Output: 13
Explanation: (11)10 = (1011)2.
After reversing the bits we get:
(1101)2 = (13)10.
Test cases:
1. 25
2. Eighteen
3. 12
4. -18
5. 34.5
30. Write a program to find whether the person is eligible for vote or not. And if that particular
person is not eligible, then print how many years are left to be eligible.
Sample Input:
Enter your age: 7
Sample output:
You are allowed to vote after 11 years
Test cases:
6. 25
7. Eighteen
8. 12
9. -18
10. 34.5

31. Find the LCM and GCD of n numbers?


Sample Input:
N value = 2
Number 1 = 16
Number 2 = 20
Sample Output:
LCM = 80
GCD = 4
Test cases:
1. N = 3, {12, 25, 30}
2. N = 2, {52, 25, 63}
3. N = 3, {17, 19, 11}
4. N = -2, {52, 60}
5. N = 2, {30, 45}

32. Write a program using function to calculate the simple interest. Suppose the customer is a
senior citizen. He is being offered 12 percent rate of interest; for all other customers, the ROI
is 10 percent.
Sample Input:
Enter the principal amount: 200000
Enter the no of years: 3
Is customer senior citizen (y/n): n
Sample Output:
Interest: 60000
Test Cases:
1. Principal: 2000 , Years: 0
2. Principal: 20000 , Years: -2
3. Principal: -2000 , Years: 2
4. Principal: 2 , Years: 2000
5. Principal: 0 , Years: 5
33. Write a program to print the Fibonacci series.
Sample Input:
Enter the n value: 6
Sample Output:
0 1 1 2 3 5

34. Java Program to Find Even Sum of Fibonacci Series Till number N?
Sample Input: n = 4
Sample Output: 33
(N = 4, So here the fibonacci series will be produced from 0th term till 8th term:0, 1, 1, 2,
3, 5, 8, 13, 21
Sum of numbers at even indexes = 0 + 1 + 3 + 8 + 21 = 33)

35. Write a program to print the numbers from M to N by skipping K numbers in between?
Sample Input:
M = 50
N = 100
K=7
Sample Output:
50, 58, 66, 74, …..
Test cases:
1. M = 15, N = 05, K = 02
2. .M = 25, N = 50, K = 04
3. M = 15, N = 100, K = -02
4. M = 0 , N = 0 , K = 2
5. M = 200 , N = 200 , K = 50

36. Write a program to print all the composite numbers between a and b?
Sample Input:
A = 12
B = 19
Sample Output
14, 15, 16, 18
Test cases:
1. A = 11, B = 11
2. A = 20, B = 10
3. A = 0, B = 0
4. A = -5, B = 5
5. A = 7, B = -12

37. Find the factorial of n?


Sample Input:
N=4
Sample Output:
4 Factorial = 24
Test cases:
1. N = 0
2. N = -5
3. N = 1
4. N = Q
5. N = 3A

38. Find the year of the given date is leap year or not
Sample Input:
Enter Date: 04/11/1947
Sample Output:
Given year is Non Leap Year
Test cases:
1. 04/11/19.47
2. 11/15/1936
3. 31/45/1996
4. 64/09/1947
5. 00/00/2000

39. Find the number of factors for the given number


Sample Input:
Given number: 100
Sample Output:
Number of factors = 9
Test cases:
1. 343
2. 1080
3. -243
4. 101010
5. 0

40. Write a program to print the given number is Perfect number or not?
Sample Input:
Given Number: 6
Sample Output:
It’s a Perfect Number
Test cases:
1. 17
2. 26!
3. 143
4. 84.1
5. -963

41. Write a program to find the square, cube of the given decimal number
Sample Input:
Given Number: 0.6
Sample Output:
Square Number: 0.36
Cube Number:0.216
Test cases:
1. 12
2. 0
3. -0.5
4. 14.25
5. -296

42. Find the nth odd number after n odd number


Sample Input: N : 7
Sample Output:
Hence the values printed for i are 1 , 3 , 5.
Test cases:
1. N = 0
2. N = -6
3. N = 2021
4. N = -14.5
5. N = -196

40 Program to find the frequency of each element in the array.


Sample Input & Output:
{1, 2, 8, 3, 2, 2, 2, 5, 1}
Pseudo:
Element | Frequency
--------------------------
1 | 2
2 | 4
8 | 1
3 | 1
4 | 1

43. Program to find whether the given number is Armstrong number or not
Sample Input:
Enter number: 153
Sample Output:
Given number is Armstrong number
Test cases:
1. 370
2. 1
3. 371
4. 145678
5. 0.21345

44. Write a program to find the sum of digits of N digit number (sum should be single digit)
Sample Input:
Enter N value: 3
Enter 3 digit numbers: 143
Test cases:
1. N = 2, 158
2. N = 3, 14
3. N = 4, 0148
4. N = 1, 0004
5. N = 4, 7263

45. Write a program to find the square root of a perfect square number(print both the positive and
negative values)
Sample Input:
Enter the number: 6561
Sample Output:
Square Root: 81, -81
Test cases:
1. 1225
2. 9801
3. 1827
4. -100
5. 0

46. Write a program to given an integer n, return true if it is a power of three. Otherwise, return
false.
Input =27
Output= true
Explanation: 27=33
Test cases:
1. 12
2. abc@45
3. 1827
4. -100
5. 0
47. Write a program to given a string paragraph and a string array of the banned words banned,
return the most frequent word that is not banned. It is guaranteed there is at least one word
that is not banned, and that the answer is unique.

Input Paragraph=”Ram hit a ball, the hit ball flew far after it was hit”,
Banned = [hit]
Output=”Ball”

48. Write a program to given a fixed-length integer array arr, duplicate each occurrence of zero,
shifting the remaining elements to the right.
Input: arr = [1, 0, 2, 3, 0, 4, 5, 0]
Output: [1, 0, 0, 2, 3, 0, 0, 4]
Explanation: After calling your function, the input array is modified to [1, 0, 0, 2, 3, 0, 0, 4]
49. Write a program to given an array nums containing n distinct numbers in the range [0, n],
return the only number in the range that is missing from the array.
Input nums = [3, 0, 1]
Output: 2
Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0, 3]. 2 is the
missing number in the range since it does not appear in nums.

50. Write a program to given an integer array nums, find the subarray with the largest sum, and
return its sum.
Input nums = [-2, 1,-3, 4,-1, 2, 1,-5, 4]
Output: 6
Explanation: The subarray [4,-1, 2, 1] has the largest sum 6.

51. Write a program to print the multiplication table of number m up to n.


Sample Input:
M=4
N=5
Sample Output:
1x4=4
2x4=8
3x4=12
4x4=16
5x4=20
Test cases:
M = 6, N = -3
M = -3, N = 5
M = 4, N = 0
M = 0, N = 0
M = -5, N = -5

52. Write Java programs to implement multiple threads and apply join method for thread and
thread has to be started after 500ms using sleep ().

53. Generate a Java code that implements java selection and iteration statements. Use do while
loop to process a menu selection. When a menu is selected, it should display the syntax of the
selected statements.

54. Create a simple generics class with type parameters for sorting values of different types.

55. Create a class name ‘overload’. Write a program to assign the values for two values by
different number of arguments using a single function.

56. Write a Java Program to count the number of words in a string using Hash Map.
57. Write a Java Program to read an email and password from excel sheet by retrieving the cell
using getRow() and getCell() method.

58. Write a Java program to sorts the given value using Hash Map.

59. Write a Java program to find distinct characters and their count in a string.

60. Write a program to print all the unique characters in a String. For instance, if the input string
is “abcb”, the output will be the characters ‘a’ and ‘c’ as they are unique. The character ‘b’
repeats twice and so it will not be printed.

You might also like