Import Java
Import Java
Import Java
Scanner;
int M = scanner.nextInt();
System.out.println("Invalid input! Please enter a number between 3 and 19 for the order of
the matrix.");
return;
A[i][j] = scanner.nextInt();
}
// Display the input matrix
System.out.println("Input Matrix:");
System.out.print(A[i][j] + "\t");
System.out.println();
System.out.print(A[i][j] + "\t");
System.out.println();
scanner.close();
OUTPUT:
m=
n=
100
No. are
11
13
31
Frequency =3
Question 2
import java.util.*;
System.out.print("Enter the size of the array (N > 2 and N < 10): ");
int N = sc.nextInt();
System.out.println("Invalid size! Size should be greater than 2 and less than 10.");
return;
a[i] = sc.nextInt();
if (a[i] <= 0) {
return;
a[j + 1] = temp;
System.out.println("Sorted array:");
System.out.println();
System.out.println("Filled Matrix:");
System.out.println();
sc.close();
OUTPUT:
Enter the size of the array (N > 2 and N < 10): 3
Sorted array:
345
Filled Matrix:
345
453
534
Question 3:
import java.util.Scanner;
int N = scanner.nextInt();
return;
remainingBoxes %= 24;
remainingBoxes %= 12;
int cartons6 = remainingBoxes / 6;
remainingBoxes %= 6;
int totalBoxes = N;
scanner.close();
OUTPUT:
Enter the number of boxes to be packed (up to 1000 boxes): 140
48 * 2 = 96
24 * 1 = 24
12 * 1 = 12
6*1=6
Remaining boxes: 2
Questions 4
import java.util.Scanner;
if (n < 4 || n % 2 != 0) {
} else {
int b = n - i;
if (k % i == 0) {
c++;
return c;
OUTPUT:
Enter the number:
30
7,23
11,19
13,17
Questions 5
import java.util.*;
class ques5
System.out.println("Enter the value for m (between 100 and 1000): "); //entering the data of m
and n
int m = sc.nextInt();
int n = sc.nextInt();
int i;
for ( i = m ; ; i++)
if (sumOfDigits(i) == n)
break;
else
System.out.println("invalid");
int s = 0;
while (n > 0)
s = s+ n % 10;
n = n / 10;
return s;
}
OUTPUT:
Enter the value for m (between 100 and 1000):
100
11
Question 6
import java.util.*;
class Ques6
return 366;
else
return 365;
int r = n%10;
return "ST";
return "ND";
else
return "TH";
int D[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
String MO[] = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
if(isLeap(y)==366)
D[2] = 29;
int m = 1;
d = d - D[m];
m++;
d = d + n;
if(d>max)
d = d - max;
y++;
compute(d,y);
else
int n = sc.nextInt();
if(n<1 || n>100)
{
System.out.println("DATE AFTER (N DAYS) OUT OF RANGE");
else
System.out.print("DATE :\t\t\t");
ob.compute(day,year);
ob.future(day,year,n);
OUTPUT:
Enter the day number : 360
Question 7
import java.util.Scanner;
System.out.print("Enter the order of the square matrix (M > 3 and M < 10): ");
int M = scanner.nextInt();
System.out.println("Invalid order! Order should be greater than 3 and less than 10.");
return;
A[i][j] = scanner.nextInt();
if (A[i][j] <= 0) {
return;
int sumDiagonal1 = 0;
int sumDiagonal2 = 0;
sumDiagonal1 += A[i][i];
System.out.println("Original Matrix:");
System.out.println();
System.out.println("\nRearranged Matrix:");
System.out.println();
scanner.close();
OUTPUT:
Enter the order of the square matrix (M > 3 and M < 10): 4
9
6
Original Matrix:
3465
7689
4566
7564
Rearranged Matrix:
3465
7689
4566
7564
3664
Sum of diagonal 1: 19
Sum of diagonal 2: 25
Questions 9
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
int n = scanner.nextInt();
System.out.println("Invalid");
else {
int i, l = 0;
a[i] = br.readLine();
int l1 = a[i].length();
if (l < l1)
l = l1;
int l1 = a[i].length();
System.out.print(a[i].charAt(j) + "\t");
System.out.println();
OUTPUT:
Enter n where 2 < n < 9:
Emus
Royald Roys
Coyote
E R C
m o o
u y y
s a o
l t
d e
s
Question 8
import java.util.Scanner;
String a = sc.nextLine();
char ch = a.charAt(a.length()-1);
System.out.println("Invalid");
else
a = a.substring(0,a.length()-1);
for(int i = 0;i<s.length;i++){
if(palin(s[i]))
System.out.print(s[i]+" ");
else
System.out.println();
for(int i = 0;i<a.length();i++)
b= a.charAt(i)+b;
return a.equals(b);
int i,l=a.length();
String p = a;
for(i=l-1;i>=0;i--)
char ch = a.charAt(i);
if(ch!=ch1)
break;
for(int j = i-1;j>=0;j--)
p= p+a.charAt(j);
return p;
OUTPUT:
Enter a sentence
help.
Helpleh
Question 10
import java.util.Scanner;
int M = scanner.nextInt();
System.out.println("Invalid input! Please enter a number between 3 and 19 for the order of
the matrix.");
return;
A[i][j] = scanner.nextInt();
}
// Display the input matrix
System.out.println("Input Matrix:");
System.out.print(A[i][j] + "\t");
System.out.println();
System.out.print(A[i][j] + "\t");
System.out.println();
scanner.close();
OUTPUT:
Enter the order of the square matrix (M x M): 3
5
6
Input Matrix:
4 3 5
6 3 7
7 8 9
5 3 4
7 3 6
9 8 7