Computer16
Computer16
Write a program in java to Declare two 2D arrays and find the multiplication of the principal Axis
elements of both the arrays and store them in a 1D array. Print the two arrays and also the 1D
array.
import java.util.Scanner;
System.out.println("Array 1:");
printArray(array1);
System.out.println("Array 2:");
printArray(array2);
printArray(result);
}
// Method to print 2D array
System.out.println();
System.out.println();
return result;
____________________________________________________________________________________________
OUTPUT
PROGRAM 17
Write a program in Java to accept 2 ranges from the user the ranges should be between 11 to
1000 find out all the mystic numbers between the ranges accepted from the user and store
them in a 2D array column major wise and find the number of even and Odd mystic numbers
separately and print their sum.
import java.util.Scanner;
// Validate ranges
System.out.println("Invalid range!");
return;
printMysticNumbers(mysticNumbers);
if (num % 2 == 0) {
evenCount++;
} else {
oddCount++;
// Display counts
int count = 0;
if (isMysticNumber(i)) {
count++;
int index = 0;
if (isMysticNumber(i)) {
mysticNumbers[index][0] = i;
index++;
return mysticNumbers;
int sum = 0;
temp /= 10;
}
return (sum == 7); // Example mystic number condition
System.out.println();
____________________________________________________________________________________________
OUTPUT
PROGRAM 18
Write a program in Java to declare a 2D array of size m×m enter values randomly into the array
display the upper part and the lower part from the intersecting point to the four corners of the
2D array find the sum of the displayed values and print the sum.
import java.util.Scanner;
int m = sc.nextInt();
int n = sc.nextInt();
array[i][j] = sc.nextInt();
}
// Print the original array
System.out.println("Original Array:");
printArray(array);
int sum = 0;
System.out.println("Upper Part:");
sum += array[i][j];
System.out.println();
System.out.println("Lower Part:");
sum += array[i][j];
System.out.println();
}
// Print the sum of displayed values
System.out.println();
____________________________________________________________________________________________
OUTPUT
PROGRAM 19
Write a program in Java to declare it to the array of size m*n take another two range from the
user and and find out all even numbers between that range include the even number into the 2D
array where size of m and n should be compatible with both the ranges.
import java.util.Scanner;
int count = 0;
if (i % 2 == 0) {
array[count / n][count % n] = i;
count++;
printArray(array);
System.out.println();
____________________________________________________________________________________________
OUTPUT
PROGRAM 20
Write a program in Java to declare a 2D array of size m into n accept the values from the user
and insert these values which are prime into the array display the array in the matrix form raw
major wise.
import java.util.Scanner;
int m = sc.nextInt();
int n = sc.nextInt();
int count = 0;
if (isPrime(i)) {
array[count / n][count % n] = i;
count++;
}
// Print the array
printArray(array);
return true;
System.out.println();
}
OUTPUT
PROGRAM 21
write a program to accept a string from the user and form a cross where the intersecting will be
accepted from the user (without using 2D array)
S S
C C
HH
OO
L L
import java.util.Scanner;
if (i == j || i + j == length - 1) {
} else {
System.out.print(" ");
}
System.out.println();
____________________________________________________________________________________________
OUTPUT
PROGRAM 22
Write a program in Java to accept a string from the user and check that the string is not more
than 100 characters including blank spaces extract each word of the string in a method void
extract() form a method arrange() with the return type and parameter in string type the original
sentence and the new sentence is displayed in the method extract() the method arrange()
rearrange each word of the sentence by placing all the vowels on the left hand side and the
consonants on the right hand side of the word if written the new word to the method extract()
where the new sentence is formed.
import java.util.Scanner;
if (isVowel(c)) {
vowels.append(c);
} else {
consonants.append(c);
newSentence.append(vowels).append(consonants).append(" ");
return newSentence.toString().trim();
c = Character.toLowerCase(c);
extract(input);
} else {
System.out.println("String exceeds 100 characters.");
____________________________________________________________________________________________
OUTPUT
PROGRAM 23
A class called stringpop is defined to handle a string related operation the members of the class
are given below:-
->void Circular() - to decode the string by replacing each Letters by converting it to opposite
case then by the next character in or circular way.
import java.util.Scanner;
String Txt;
public Stringpop() {
Txt = null;
Txt = sc.nextLine();
}
public char CaseConvert() {
if (Txt != null) {
if (Character.isUpperCase(c)) {
newStr.append(Character.toLowerCase(c));
} else if (Character.isLowerCase(c)) {
newStr.append(Character.toUpperCase(c));
} else {
newStr.append(c);
Txt = newStr.toString();
if (Txt != null) {
char c = Txt.charAt(i);
if (Character.isLetter(c)) {
newChar = 'a';
decodedStr.append(newChar);
} else {
decodedStr.append(c);
Txt = decodedStr.toString();
sp.readString();
sp.CaseConvert();
sp.Circular();
}
OUTPUT
PROGRAM 24
Write a program in Java to enter a string from the user and a number from the user the number
should be within range from 1 to 25 from the new string by chain in each characters at the nth
position in the alphabetical order display all new string.
import java.util.Scanner;
} else {
if (Character.isLetter(c)) {
} else {
shiftedStr.append(c);
}
____________________________________________________________________________________________
OUTPUT
PROGRAM 25
Write a method to declare a 2D array of integer type insert the values into the array within the
method void get() and initialise the values of m and n which stands for the rows and columns in
the constructor write another method int display() that returns an array that holds the transpose
value of the array that has been declared to the main method where both the arrays are
displayed.
import java.util.Scanner;
int[][] arr;
int m, n;
this.m = m;
this.n = n;
arr[i][j] = sc.nextInt();
}
public int[][] display() {
transpose[j][i] = arr[i][j];
return transpose;
int m = sc.nextInt();
int n = sc.nextInt();
ta.get();
System.out.println("Original Array:");
System.out.println();
System.out.println("Transposed Array:");
System.out.println();
____________________________________________________________________________________________
OUTPUT