Java P Code
Java P Code
import java.util.Scanner;
input.close();
}
}
No 5
import java.util.Scanner;
if (array1.length != array2.length) {
areEqual = false;
} else {
for (int i = 0; i < size; i++) {
if (array1[i] != array2[i]) {
areEqual = false;
break;
}
}
}
if (areEqual) {
System.out.println("The arrays are equal.");
} else {
System.out.println("The arrays are not equal.");
}
input.close();
}
}
No 6
import java.util.Scanner;
input.close();
}
}
NO 7
import java.util.Scanner;
input.close();
}
}
No 8
import java.util.Scanner;
myBox.calculateVolume();
input.close();
}
}
NO 9
import java.util.Scanner;
while (continueChecking) {
System.out.print("Enter a number (or enter 0 to exit): ");
int number = input.nextInt();
if (number == 0) {
continueChecking = false;
} else {
if (isPrime(number)) {
System.out.println(number + " is a prime number.");
} else {
System.out.println(number + " is not a prime number.");
}
}
}
input.close();
}
while (continueChecking) {
System.out.print("Enter a month (1-12) or 0 to exit: ");
int month = input.nextInt();
if (month == 0) {
continueChecking = false;
} else {
String season = determineSeason(month);
System.out.println("The season for month " + month + " is " + season);
}
}
input.close();
}
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
break;
case 3:
case 4:
case 5:
season = "Spring";
break;
case 6:
case 7:
case 8:
season = "Summer";
break;
case 9:
case 10:
case 11:
season = "Autumn";
break;
default:
season = "Invalid Month";
break;
}
return season;
}
}
NO 12
class Employee {
private String name;
private int yearOfJoining;
private double salary;
private String address;
System.out.println("Employee Information:");
System.out.println("-----------------");
employee1.displayInfo();
employee2.displayInfo();
employee3.displayInfo();
}
}
NO 13
import java.util.Scanner;
input.close();
}
}