0% found this document useful (0 votes)
68 views9 pages

Java Matrix Multiplication Programs

The document provides 77 programming problems covering a variety of concepts including arrays, strings, patterns, mathematics, and more. The problems range in complexity from basic programs like calculating area to more advanced topics like matrix operations. Sample inputs and outputs are provided for many problems to illustrate the required logic and output format. The problems cover both basic programming concepts as well as more complex algorithms and data structures.

Uploaded by

Rajkumar
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)
68 views9 pages

Java Matrix Multiplication Programs

The document provides 77 programming problems covering a variety of concepts including arrays, strings, patterns, mathematics, and more. The problems range in complexity from basic programs like calculating area to more advanced topics like matrix operations. Sample inputs and outputs are provided for many problems to illustrate the required logic and output format. The problems cover both basic programming concepts as well as more complex algorithms and data structures.

Uploaded by

Rajkumar
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

Sample Programs for Practice 

1) Write a single program to generate a multiplicaiton and subtraction table for a given
number.

2) Write a program to print a letters from the user input character to 'Z' without using
strings.
Example 1:  input : X
Output : XYZ 

Example 2:  Input : M
Output : MNOPQRSTUWXYZ 

3) write a program to find the difference between the given number and it's reverse
number.
Example 1: Input : 12345 
Output : 12345 - 54321 = -41976 

Example 2: Input : 543 
Output : 543 - 345 = 198 

4) Write a program to define the functionality of a Bitwise operators.

5) Write a program to print the following pattern based on the alphabet.
Example 1:
Input: E 
Output: 
EEEEE
DDDD 
CCC 
BB 

Example 2: 
Input:C 
 

Output: 
CCC 
BB 

 
6) Write a program for the following. Let consider 20 students in a class with the roll no 
101-120. We are going to split them into four groups. Based on their roll number we are 
going to split them with the following logics. 
Example 1: 
Input : Total Number of students : 20  
Output: 
Group 1:
101 
105 
109 
113 
117 
 
Group 2:
102 
106 
110 
114 
118 
 
Group 3:
103 
107 
111 
115 
119 
 
Group 4:
104 
108 
112 
116 

 
 

120 
 
7) Write a program to print the following output for the given input. You can assume the 
string is of odd length 
Eg 1:  Input: 12345
        Output:
1       1
  2   2
    3
  4   4
5        5 
 
8) Write a program to demonstrate the functionalities of static keyword. 
 
9) Given two sorted arrays, merge them such that the elements are not repeated 
Example 1:   
Input: Array 1: 2,4,5,6,7,9,10,13
         Array 2: 2,3,4,5,6,7,8,9,11,15
Output: Merged array: 2,3,4,5,6,7,8,9,10,11,13,15  
 
10) Alternate sorting: Given an array of integers, rearrange the array in such a way that 
the first element is first maximum and second element is first minimum. 
 Example:  Input : {1, 2, 3, 4, 5, 6, 7}
  Output: {7, 1, 6, 2, 5, 3, 4}  
 
11) Java Program to left rotate the elements of a multidimensional array. 
12) Write a program to print the number 7.50 without using String. 
13) Write a program to find the area of the square 
14) Write a program to find the area of the rectangle 
15) Write a program to find the area of the cylinder 
16) Write a program to evaluate the polynomial equation  

 
 

 
 
17) Given the radius of two concentric circle, find the area of the space between the 
circles. 
18) Evaluate the following expression on paper and on program and understand the 
difference 
i) ++a-b–                   ii) a%b++     iii)  a*=b+5               iv) x=69>>>2 
 
19) Evaluate the following expression on paper and on program and understand the 
difference 
a+=a++ + ++a + –a + a–; when a=28 
 
20) Evaluate the following expression on paper and on program and understand the 
difference 
x = x++ * 2 + 3 * –x; 
 
21) Evaluate the following expression on paper and on program and understand the 
difference 
If int y = 10 then find int z = (++y * (y++ + 5)); 
 
22) Evaluate the following expression on paper and on program and understand the 
difference 
23) What is the value of x1 if x=5 ? 

 
 

x1=++x – x++ + –x 
24) Program to Find ASCII Value of a Character 
25) Program to Compute Quotient and Remainder 
26) Program to Demonstrate the Working of Keyword long 
27) Program to Swap Two Numbers 
28) Program to Check Whether a Number is Even or Odd 
29) Program to Check Whether a Character is a Vowel or Consonant 
30) Program to Find the Largest Number Among Three Numbers 
31) Program to Find the Roots of a Quadratic Equation 
32) Program to Check Whether a Number is Positive or Negative 
33) Program to Check Whether a Character is an Alphabet or not 
34) Program to Calculate the Sum of Natural Numbers and find the largest digit of the 
sum. 
35) Program to Find Factorial of a Number and the factorial number's sum of digits. 
36) Java Program to print the elements of an array present on even position 
37) Java Program to print the elements of an array present on odd position 
38) Java Program to print the largest element in an array 
39) Java Program to print the smallest element in an array 
40) Java Program to print the number of elements present in an array 
41) Java Program to copy all elements of one array into another array 
42) Java Program to find the frequency of each element in the array 
43) Java Program to left rotate the elements of an array 
44) Java Program to print the duplicate elements of an array 
45) Java Program to print the sum of all the items of the array 
46) Java Program to rotate the elements of an array in the right direction 
47 - 50) Write a programs to print following patterns 
 

 
 

 
 
51) Write a program to display the number in reverse order without use of String 
functions. 
Eg 1:  Input: 12345 
Output :The number in reverse order is : 54321 
 
52) Using Recursion reverse the string such as 
Eg 1:  Input: one two three
       Output: three two one
Eg 2:  Input: I love india
       Output: india love I  
 
53) Write a program to give the following output for the given input: 
Eg 1:  Input: a1b10
Output: abbbbbbbbbb
Eg: 2:  Input: b3c6d15
           Output: bbbccccccddddddddddddddd
The number varies from 1 to 99. 
 
54) Write a program to sort the elements in odd positions in descending order and 
elements in ascending order. 
Eg 1:  Input:  13,2 4,15,12,10,5
         Output: 13,2,12,10,5,15,4
Eg 2:  Input: 1,2,3,4,5,6,7,8,9
         Output: 9,2,7,4,5,6,3,8,1  
 
 

 
 

55) Write a program to print the alphabet 'C' with the stars based on the given numbers 
Eg 1:  Input: 4
        Output:
****


****  
 
56) Write a program to make such a pattern like a pyramid with numbers increased by 1. 
Eg:  Input : 10 
Output: 
     1  
    2 3  
  4 5 6  
7 8 9 10  
 
57) Write a program to print the following output for the given input. You can assume 
the string is of odd length 
Eg 1:  Input: 12345
        Output:
1       5
  2   4
    3
  2   4
1        5 
 
58) Write a program to print the following pattern for the given input number. 
Eg 1:  Input: 4
        Output:  
******** 
***__***
**____**
*______*
**____**
***__***
******** 
 

 
 

59) Find if a String2 is substring of String1. If it is, return the index of the first 
occurrence. else return -1. 
Eg 1: Input: String 1: test123string
          String 2: 123
         Output: 4
Eg 2:  Input: String 1: testing12
         String 2: 1234 
         Output: -1 
 
60) Write a program to find the sum of the series. The series will be like 1 +11 + 111 + 
1111 +.. n terms.  
Eg 1: Input:  Input the number of terms : 5 
Output :  
1 + 11 + 111 + 1111 + 11111 
The Sum is : 12345 
 
Eg 2: Input:  Input the number of terms : 3 
Output :  
1 + 11 + 111 
The Sum is : 123 
 
 
 
Programs on Arrays and Strings: Write minimum 2 different versions of java programs 
for each question. 
61. Java Program to print the elements of an array in reverse order 
62. Java Program to print the elements of an array present on even position and odd 
positions 
63. Java Program to print the largest element and smallest element in an array 
64. Java Program to copy all elements of one array into another array 
65. Java Program to find the frequency of each element in the array 
66. Java Program to left rotate the elements of an array 
67. Java Program to print the duplicate elements of an array 
68. Java Program to print the sum of all the items of the array 
69. Java Program to rotate the elements of an array in the right direction 
70. Java Program to find the 2nd Largest Number in an Array 
71. Java Program to find the 2nd Smallest Number in an Array 

 
 

72. Java Program to remove Duplicate Element in an Array 
73. Java Program to add two matrices 
74. Java Program to find the product of two matrices 
75. Print Odd and Even Number from an Array 
76. Java Program to display the transpose matrix 
77. Java Program to sort the elements of an array in ascending order 
78. Java Program to subtract the two matrices 
79. Java Program to determine whether a given matrix is an identity matrix 
80. Java Program to determine whether a given matrix is a sparse matrix 
81. Java Program to determine whether two matrices are equal 
82. Java Program to display the lower triangular matrix 
83. Java Program to display the upper triangular matrix 
84. Java Program to find the frequency of odd & even numbers in the given matrix 
85. Java Program to find the sum of each row and each column of a matrix 
[Link] Program to print all the characters in an arrays. 
[Link] Program to convert char array to string without using toString() method. 
[Link] Program to convert a sentence/paragraph to word(String) array with using 
string function.  
89. Java Program to convert a sentence/paragraph to word(String) array without 
using string function.  
90. Java Program to sort the words in ascending.  
91. Java Program to sort the characters in a word in descending.  
92. Java Program to sort the words in ascending using recursion. 
93. Java Program to sort the characters in a word in descending using recursion. 
[Link] Program to find the given two strings are anagram to each other 
95. Java Program to find the given two strings are palindrome. 
[Link] program to find a character in a word string linear search. 
97. Java program to find a character in a given string using binary search. 
[Link] Program to print the print the equivalent Capital letter of a given small letter 
in Alphabets. 
[Link] Program to convert all small letter to capital letter without using special 
functions. 
100. Java Program to convert ASCHII value to character(for A-Z only) without 
using special function 

Common questions

Powered by AI

The logic involves assigning students into four groups, each group receiving students in a round-robin fashion. With roll numbers assigned from 101 to 120, the first group begins with student 101, the second with 102, the third with 103, and so on. After a cycle through all groups, the process repeats by incrementing roll numbers by four. Thus, Group 1 will have 101, 105, 109, 113, and 117. Group 2 will consist of 102, 106, 110, 114, and 118. Group 3 will include 103, 107, 111, 115, and 119. Lastly, Group 4 includes roll numbers 104, 108, 112, 116, and 120 .

To merge two sorted arrays without duplicates, iterate through both arrays simultaneously and compare their elements. Add the smaller element to the new array and move to the next element in that array. If the elements are equal, add only one element and move to the next element in both arrays. Continue this process until all elements from both arrays have been considered. The resulting array contains all unique elements from both input arrays. For example, merging [2,4,5,6,7] and [2,3,4,5,6] results in [2,3,4,5,6,7].

To evaluate expressions such as "a+=a++ + ++a + –a + a–;" or "x = x++ * 2 + 3 * –x;", one must account for operator precedence and side effects, particularly with increment/decrement operators. On paper, manually resolve the expression step-by-step following these rules. In a program, the compiler's order of operations may differ due to language-specific behaviors, thus yielding different results. This discrepancy highlights the importance of understanding compiler behavior and may involve step-debugging to verify each computational stage .

To find the difference between a number and its reverse, one should first reverse the digits of the number programmatically. This involves extracting each digit from the original number starting from the last digit and constructing the reversed number. Once the reversed number is constructed, subtract it from the original number. For example, if the input is 123, the reverse is 321. The difference is then calculated as 123 - 321 = -198 .

In programming, the 'static' keyword is used to enable a method or variable to belong to the class rather than to instances of the class. Static members are shared among all instances. Demonstrating it involves creating a class with both static and instance variables or methods, and showing that changes in static members reflect across all instances of the class while instance members vary per object. A designated 'main' method could create multiple instances of the class, manipulating and printing both static and non-static members to illustrate the difference .

Alternating sorting places the maximum value first, minimum second, and repeats this pattern. First, sort the array in ascending order, then reconstruct the array by selecting elements from the end (maximum) and beginning (minimum) alternately. Maintain two pointers, one starting at the beginning and the other at the end of the sorted array, to facilitate selection. The result is a zigzag pattern of maximum, minimum, next maximum, and so forth .

To find the second largest and smallest numbers, first sort the array in ascending order. The second element in the sorted array corresponds to the second smallest, and the second-to-last element corresponds to the second largest number. Alternatively, traverse the array twice; once to determine the largest and smallest numbers, then ignore those during a second pass to find the next largest and smallest values through comparison .

An identity matrix has ones on its main diagonal and zeros elsewhere. Programmatically, iterate through each element—checking if all elements on the main diagonal are one and all other elements are zero. A sparse matrix has most elements as zero, commonly fewer than a predefined threshold of non-zero entries. Count non-zero elements and compare against the total number of elements to determine sparsity. Each check can leverage nested loops iterating over matrix rows and columns effectively distinguishing between matrix types .

Without using string functions, one needs to manually parse the input by examining each character. Initialize an empty list to hold words. Iterate over characters, append to a current word variable until encountering white space, at which point add the current word to the list and reset it. Continue until the end of the input, then convert the list into an array. This manual approach mirrors functions like split() and ensures no built-in string manipulation methods are used .

To calculate the area between two concentric circles, calculate the area of both circles using the formula for the area of a circle (πr²). The radius of the smaller circle is subtracted from the radius of the larger circle. The difference in areas between the larger circle and the smaller circle gives the area of the ring-shaped region between them. For example, if the radius of the larger circle is R and the smaller is r, the area is π(R² - r²).

You might also like