NFJJDJJSJJ OK
NFJJDJJSJJ OK
import java.util.Scanner;
public class T1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int summation= 0;
System.out.println("Enter 10 numbers:");
if (c > 0) {
double average = (double) summation / c;
System.out.println("Sum = " + summation);
System.out.println("Minimum = " + minimum);
System.out.println("Maximum = " + maximum);
System.out.println("Average = " + average);
} else {
System.out.println("No odd positive numbers found");
}
}
}
Task 2
import java.util.Scanner;
public class T2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int primeC = 0;
if (isPrime) {
primeC++;
}
}
System.out.println("There are " + primeC + " prime numbers between " + num1
+ " and " + num2+ ".");
}
}
Task 3
import java.util.Scanner;
public class T3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sumAscii = 0;
for (int i = 0; i < stringConcatenation.length(); i++) {
char ch = stringConcatenation.charAt(i);
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
sumAscii += ch;
}
}
}
}
Task 4
import java.util.Scanner;
public class T4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if (ch == 'a') {
res += 'z';
} else {
res += (char) (ch - 1);
}
} else {
res += ch;
}
}
}
}
Task 5
import java.util.Scanner;
public class T5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Reversed array:");
for (int j = 0; j < len; j++) {
System.out.print(arr[j] + " ");
}
}
}
Task 6
import java.util.Scanner;
public class T6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
}
}
Task 7
import java.util.Scanner;
public class T7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
}
}
Task 8
import java.util.Scanner;
public class T8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("2D Array:");
for (int j = 0; j < r; j++) {
for (int k = 0; k < c; k++) {
System.out.print(arr2[j][k] + " ");
}
System.out.println();
}
System.out.println("1D Array:");
for (int j = 0; j < arr1.length; j++) {
System.out.print(arr1[j] + " ");
}
}
}
Task 9
public class T9 {
int[][] mat1 = {
{1, 0, 0, 1},
{0, 1, 0, 0},
{1, 0, 1, 0},
{0, 1, 0, 1}
};
int[][] mat2 = {
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
};
checkIdentityMatrix(mat1);
checkIdentityMatrix(mat2);
}
if (j == k && mat[j][k] != 1) {
isIdentityMatrix = false;
break;
}
if (j != k && mat[j][k] != 0) {
isIdentityMatrix = false;
break;
}
}
if (!isIdentityMatrix) {
break;
}
}
if (isIdentityMatrix) {
System.out.println("Identity Matrix");
} else {
System.out.println("Not an Identity Matrix");
}
}
}
Task 10
import java.util.Scanner;
int[][] arr2D = {
{0, 0, 10, 0, -1},
{0, -1, 0, 0, -1},
{-1, 0, -1, 0, 0},
{0, -1, 7, 0, -1},
{0, -1, 0, -1, 0}
};
System.out.println("Initial Map:");
printMap(arr2D);
int turns = 5;
boolean treasureDiscovered = false;
if (inp.equals("UP")) {
new_row--;
} else if (inp.equals("DOWN")) {
new_row++;
} else if (inp.equals("LEFT")) {
new_col--;
} else if (inp.equals("RIGHT")) {
new_col++;
} else {
System.out.println("That’s not a valid move. Please try again.");
continue;
}
if (new_row < 0 || new_row >= row || new_col < 0 || new_col >= col) {
System.out.println("You have stepped outside the grid! The game is
over.");
break;
}
if (arr2D[new_row][new_col] == -1) {
System.out.println("You hit a mine! The game is over.");
break;
} else if (arr2D[new_row][new_col] == 10) {
System.out.println("Well done! You discovered the treasure!");
treasureDiscovered = true;
} else {
arr2D[row_pos][col_pos] = 0;
arr2D[new_row][new_col] = 7;
row_pos = new_row;
col_pos = new_col;
System.out.println("Current state:");
printMap(arr2D);
}
turns--;
}