uk11
mport java.util.Scanner;
interface Operation {
double volume();
}
class Cylinder implements Operation {
public static final double PI = 3.142;
private double radius;
private double height;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
@Override
public double volume() {
return PI * radius * radius * height;
}
}
public class Main {
public static void main(String[] args) {
// Read radius and height from user input
Scanner scanner = new Scanner(System.in);
System.out.print("Enter radius: ");
double radius = scanner.nextDouble();
System.out.print("Enter height: ");
double height = scanner.nextDouble();
// Create a new Cylinder object with user-specified radius and height
Cylinder cylinder2 = new Cylinder(radius, height);
// Calculate and print the volume of the second cylinder
System.out.println("Volume of second cylinder: " + cylinder2.volume());
}
}
Q2)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
if (!username.equals(password)) {
System.out.println("Invalid password");
}
}
}