Avi Oops
Avi Oops
import java.util.Random;
Output:
Output:
Output:
import java.util.Scanner;
int sum = 0;
for (int num : arr) {
sum += num;
}
double average = (double) sum / n;
Output:
Output:
Design a class that performs string operations (Equal, Reverse the string,
Change case)
Output:
Demonstrate the use of final keyword with data member, function & class
Output:
Demonstrate the use of keywords try, catch, finally, throw & throws
import java.util.Scanner;
try {
System.out.print("Enter first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter second number: ");
int num2 = scanner.nextInt();
Output:
@Override
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println(threadName + ": " + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Output:
while (gameRunning) {
System.out.println("Player " + currentPlayer + "'s turn.");
System.out.print("Enter row number (0-2): ");
int row = scanner.nextInt();
System.out.print("Enter column number (0-2): ");
int col = scanner.nextInt();
if (isValidMove(row, col)) {
makeMove(row, col);
displayBoard();
if (isWinner()) {
System.out.println("Player " + currentPlayer + " wins!");
gameRunning = false;
} else if (isBoardFull()) {
System.out.println("It's a draw!");
gameRunning = false;
} else {
switchPlayer();
}
} else {
System.out.println("Invalid move! Please try again.");
}
}
Name: PRANAY SHARMA Enrolment No.: 04415611922 Section: S11
scanner.close();
}
}
Name: PRANAY SHARMA Enrolment No.: 04415611922 Section: S11
}
return false;
}
Design a program to read a text file and after printing that on screen, write
the content to another file
import java.io.*;
try {
FileReader fileReader = new FileReader(inputFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
System.out.println("Content of input file:");
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
bufferedReader.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
Output:
} catch (IOException e) {
e.printStackTrace();
}
}