Java Practical
Java Practical
Solution:-
Here’s a simple Java program that performs the specified operations on two numbers input by the user:
import java.util.Scanner;
// Addition
// Subtraction
// Multiplication
// Division
if (num2 != 0) {
double quotient = num1 / num2;
} else {
scanner.close();
Aim:- Write a program to convert temperature from Fahrenheit to Celsius degree using Java.
Solution:-
Here’s a simple Java program that converts temperature from Fahrenheit to Celsius:
Import java.util.Scanner;
Scanner.close();
Import java.util.Scanner;
// Sample array
If (array[i] == elementToFind) {
Index = I;
If (index != -1) {
} else {
Scanner.close();
}
Aim:-Write a Java program that prints current time in GMT.
Solution:-
You can use the java.time package to get the current time in GMT. Here’s a simple Java program:
Import java.time.ZoneId;
Import java.time.ZonedDateTime;
Import java.time.format.DateTimeFormatter;
Import java.util.Arrays;
// Sample array
// Element to remove
If (array[i] == elementToRemove) {
indexToRemove = I;
break;
If (indexToRemove != -1) {
} else {
Aim:-To write and read a plain text file, write a Java program.
Solution:-
Below is a simple Java program that demonstrates writing and reading a plain text file:
Import java.io.BufferedReader;
Import java.io.BufferedWriter;
Import java.io.FileReader;
Import java.io.FileWriter;
Import java.io.IOException;
Writer.write(content);
} catch (IOException e) {
String line;
Content.append(line).append(“\n”);
} catch (IOException e) {
Return content.toString();
// Sample array
copy[i] = original[i];
return copy;
result.append(array[i]);
if (i < array.length - 1) {
result.append(", ");
result.append("]");
return result.toString();
scanner.close();