Posts

Showing posts from September, 2024

Question Program

Image
 import java.lang.*; import java.io.*; class Questions {     public String[][] qpa; // Questions and possible answers     public String[][] qca; // Correct answers     Questions() throws IOException {         qpa = new String[10][5]; // Initialize the question and answers array         /* Questions and Objectives */         qpa[0][0] = "What is the size of an int in Java?";          qpa[0][1] = "1. 2 bytes";          qpa[0][2] = "2. 4 bytes";          qpa[0][3] = "3. 8 bytes";          qpa[0][4] = "4. Depends on the system";         qpa[1][0] = "Which of these is a valid declaration of a char?";          qpa[1][1] = "1. char ch = 'ab';";          qpa[1][2] = "2. char ch = '\\u0022';";          qpa[1][3...

File operations

Image
 import java.io.*; import java.util.Scanner; public class FileOperations {     private static final String FILE_PATH = "example.txt";     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);         int choice;         while (true) {             System.out.println("Choose an operation:");             System.out.println("1. Read from file");             System.out.println("2. Write to file");             System.out.println("3. Update file");             System.out.println("4. Delete file");             System.out.println("5. Exit");             choice = scanner.nextInt();             scanner.nextLine();  // Consume newline ...