Posts

Showing posts from October, 2025

slip 25

1.... import java.io.* ; class Except { public static void main(String args[])throws Exception { InputStreamReader r=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(r); System.out.println(“Enter name:”); String name = br.readLine(); System.out.println(“Enter roll no.:”); String number=br.readLine(); System.out.println(“Enter marks:”); String marks=br.readLine(); System.out.println(“name:”+name); System.out.println(“Roll No.:”+number); System.out.println(“Marks:”+marks); } } 2. import javax.swing.*; import java.awt.*; import java.awt.event.*; class seta3 extends JFrame implements ActionListener {  private JLabel l1,l2,l3;  private JButton b;  private JRadioButton r1,r2,r3;  private JCheckBox c1,c2,c3;  private JTextField t1,t2;  private ButtonGroup b1;  private JPanel p1,p2;1  private StringBuffer s1=new StringBuffer();  public seta3(String s)  {   super(s);   b1=new ButtonGroup();   p1=new JPanel(); ...

slip No.17

1. import java.util.Scanner; class Customer {  String name;  String phoneNumber;  void readCustomer(Scanner sc) {  System.out.print("Enter Customer Name: ");  name = sc.nextLine();  System.out.print("Enter Phone Number: ");  phoneNumber = sc.nextLine();  }  void displayCustomer() {  System.out.println("Customer Name : " + name);  System.out.println("Phone Number : " + phoneNumber);  } } class Depositor extends Customer {  String accno; double balance;  void readDepositor(Scanner sc) {  readCustomer(sc);  System.out.print("Enter Account Number: ");  accno = sc.nextLine();  System.out.print("Enter Balance: ");  balance = sc.nextDouble();  sc.nextLine(); // consume newline  }  void displayDepositor() {  displayCustomer();  System.out.println("Account Number : " + accno);  System.out.println("Balance : " + balance);  } } class Borro...

slip.16

1. import java.util.Scanner; @FunctionalInterface interface Square {  int calculate(int x); } public class SquareUsingInterface {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in); Square s = (int x) -> x * x;  System.out.print("Enter a number: ");  int num = sc.nextInt();    int result = s.calculate(num);  System.out.println("Square of " + num + " is: " + result);  sc.close();  } } 2. import java.awt.*; import java.awt.event.*; public class AWTMenuExample {  Frame frame;  public AWTMenuExample() {  frame = new Frame("Java AWT Examples");    MenuBar menuBar = new MenuBar();    Menu fileMenu = new Menu("File");  MenuItem newItem = new MenuItem("New", new MenuShortcut(KeyEvent.VK_N));   MenuItem openItem = new MenuItem("Open"); MenuItem saveItem = new MenuItem("Save");  CheckboxMenuItem showAbout = new CheckboxMenuItem("Show Ab...

slip.14

1. import java.util.Scanner; class ZeroException extends Exception {  public ZeroException(String message) {  super(message);  } } public class PrimeCheck {    public static boolean isPrime(int n) {  if (n <= 1) return false;  for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) return false;  }  return true;  }  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter a number: ");  int num = sc.nextInt();  try {  if (num == 0) {  throw new ZeroException("Number is 0");  }  if (isPrime(num)) {  System.out.println(num + " is a prime number.");  } else {  System.out.println(num + " is not a prime number.");  }  } catch (ZeroException e) {  System.out.println("Exception: " + e.getMessage());  } finally {  sc.close();  }  } } 2. Step 1: Package SY File: SY/S...

slip No.11

1. import java.util.Scanner; interface Operation {  double PI = 3.142;   double volume();  } class Cylinder implements Operation {  private double radius;  private double height;    public Cylinder(double radius, double height) {  this.radius = radius;  this.height = height;  }  public double volume() {  return PI * radius * radius * height;  } } public class CylinderDemo {  public static void main(String[] args) { Scanner sc = new Scanner(System.in);  System.out.print("Enter radius of cylinder: ");  double r = sc.nextDouble();  System.out.print("Enter height of cylinder: ");  double h = sc.nextDouble();  Cylinder cylinder = new Cylinder(r, h);  System.out.println("Volume of the cylinder: " + cylinder.volume());  sc.close();  } } 2. import java.util.Scanner; class InvalidPasswordException extends Exception {  public InvalidPasswordException(S...

slip.10

1. import java.util.Scanner; @FunctionalInterface interface CubeCalculator {  int cube(int n); } public class CubeFunctionalInterface {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter a number: ");  int num = sc.nextInt();  CubeCalculator cubeCalc = n -> n * n * n;  int result = cubeCalc.cube(num);  System.out.println("Cube of " + num + " is: " + result);  sc.close();  } } 2. Step 1: Create package student File: StudentInfo.java package student; public class StudentInfo {  private int rollNo;  private String name;  private String className;  private double percentage;    public StudentInfo(int rollNo, String name, String className, double percentage) {  this.rollNo = rollNo;  this.name = name;  this.className = className;  this.percentage = percentage;  }    public void display() { ...

slip.8

1. import java.util.Scanner; class Sphere {  private double radius;    public Sphere(double radius) {  this.radius = radius;  }    public double surfaceArea() {  return 4 * Math.PI * radius * radius; }    public double volume() {  return (4.0 / 3.0) * Math.PI * radius * radius * radius;  }    public void display() {  System.out.println("Radius of Sphere: " + radius);  System.out.println("Surface Area : " + surfaceArea());  System.out.println("Volume : " + volume());  } } public class SphereTest {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter radius of the sphere: ");  double r = sc.nextDouble();  Sphere sphere = new Sphere(r);  sphere.display();  sc.close();  } } 2. import java.awt.*; import java.awt.event.*; public class MouseEventDemo extends Frame implements MouseListen...

slip.6

1. class Employee {  int empId;  String empName;  String empDesignation;  double empSalary;    Employee(int empId, String empName, String empDesignation, double empSalary) {  this.empId = empId;  this.empName = empName;  this.empDesignation = empDesignation;  this.empSalary = empSalary;  }    public String toString() {  return "Employee ID: " + empId +  "\nEmployee Name: " + empName +  "\nDesignation: " + empDesignation +  "\nSalary: " + empSalary;  } } public class EmployeeTest {  public static void main(String[] args) {    Employee e1 = new Employee(101, "Rahul Sharma", "Manager", 55000.50);  Employee e2 = new Employee(102, "Priya Verma", "Developer", 45000.75);  // Printing employee details using toString()  System.out.println("=== Employee 1 ===");  System.out.println(e1);  System.out.println("\n=== Employee 2 ===");  ...

slip.5

1. class Continent {  String continentName;  Continent(String continentName) {  this.continentName = continentName;  } } class Country extends Continent {  String countryName; Country(String continentName, String countryName) {  super(continentName);  this.countryName = countryName;  } } class State extends Country {  String stateName;  State(String continentName, String countryName, String stateName) {  super(continentName, countryName);  this.stateName = stateName;  } } class Place extends State {  String placeName;  Place(String continentName, String countryName, String stateName, String placeName) {  super(continentName, countryName, stateName);  this.placeName = placeName;  }  void display() {  System.out.println("Continent: " + continentName);  System.out.println("Country : " + countryName);  System.out.println("State : " + stateName);  S...

slip.4

1. import java.util.Scanner; public class Transpose {  public static void main(String args[])  { int i, j; System.out.println("Enter total rows and columns: "); Scanner s = new Scanner(System.in); int row = s.nextInt(); int column = s.nextInt(); int array[][] = new int[row][column]; System.out.println("Enter matrix:"); for(i = 0; i < row; i++) {  for(j = 0; j < column; j++)  {  array[i][j] = s.nextInt();  System.out.print(" ");  } } System.out.println("The above matrix before Transpose is "); for(i = 0; i < row; i++) {  for(j = 0; j < column; j++)  {  System.out.print(array[i][j]+" ");  }  System.out.println(" ");  } System.out.println("The above matrix after Transpose is "); for(i = 0; i < column; i++) {  for(j = 0; j < row; j++)  {  System.out.print(array[j][i]+" ");  }  System.out.println(" ");  }  } } 2. import java.awt.*; imp...

slip.3

1. import java.util.Arrays; import java.util.Scanner; public class CitySort {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter number of cities: ");  int n = sc.nextInt();  sc.nextLine();   String[] cities = new String[n];  System.out.println("Enter the city names:");  for (int i = 0; i < n; i++) {  cities[i] = sc.nextLine();  } Arrays.sort(cities);  System.out.println("\nCities in ascending order:");  for (String city : cities) {  System.out.println(city);  }  sc.close();  } } 2. import java.util.Scanner; class CovidPositiveException extends Exception {  public CovidPositiveException(String message) {  super(message);  } } class Patient {  String patient_name;  int patient_age;  int patient_oxy_level;  int patient_HRCT_report;  Patient(String name, int age, int oxy, int hrct)...

slip.2

1. public class BMI_Calculator {  public static void main(String[] args) {    if (args.length < 4) {  System.out.println("Usage: java BMI_Calculator <FirstName> <LastName> <WeightKg> <HeightMeters>");  return;  }    String firstName = args[0];  String lastName = args[1];  double weight = Double.parseDouble(args[2]); double height = Double.parseDouble(args[3]);   double bmi = weight / (height * height);    System.out.println("Name: " + firstName + " " + lastName);  System.out.println("Weight: " + weight + " kg");  System.out.println("Height: " + height + " m");  System.out.printf("BMI Index: %.2f%n", bmi);    if (bmi < 18.5)  System.out.println("Category: Underweight");  else if (bmi < 24.9)  System.out.println("Category: Normal weight");  else if (bmi < 29.9)  System.out.println("Category: Overweight");  els...

slip.1

Slip No.1 1. import java.util.Scanner; public class PrimeNumbers {  public static void main(String[] args) {  Scanner sc = new Scanner(System.in);  System.out.print("Enter the number of elements: ");  int n = Integer.parseInt(args[0]);  int[] arr = new int[n];  System.out.println("Enter the elements in the array: ");  for (int i = 0; i < n; i++) {  arr[i] = sc.nextInt();  }  System.out.println("Prime numbers in the array:");  for (int i = 0; i < n; i++) {  if (isPrime(arr[i])) {  System.out.println(arr[i]);  }  }  sc.close();  }  public static boolean isPrime(int num) {  if (num <= 1) return false;  for (int i = 2; i <= Math.sqrt(num); i++) {  if (num % i == 0) return false;  }  return true;  } } 2. import java.util.Scanner; abstract class Staff {  protected int id;  protected String name;  Staff(int id, String name) {  this.id = id;...