Category: Java


  • import java.util.Scanner; public class MatrixOperations { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println(“Enter the number of rows and columns of the first matrix:”); int rows1 = scanner.nextInt(); int cols1 = scanner.nextInt(); int[][] matrix1 = new int[rows1][cols1]; System.out.println(“Enter the elements of the first matrix:”); for (int i = 0; i <…

  • Write a program to implement Boolean AND, OR, XOR, and NOT operations.

    public class BooleanOperations { // Method for AND operation public static boolean andOperation(boolean a, boolean b) { return a && b; } // Method for OR operation public static boolean orOperation(boolean a, boolean b) { return a || b; } // Method for XOR operation public static boolean xorOperation(boolean a, boolean b) { return a…

  • import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Date { private int day; private int month; private int year; public Date(int day, int month, int year) { this.day = day; this.month = month; this.year = year; } public void addDays(int days) { LocalDate currentDate = LocalDate.of(year, month, day); LocalDate newDate = currentDate.plusDays(days); this.day = newDate.getDayOfMonth(); this.month =…

  • Students are required to develop the following type of programs in Java language with internaldocumentation:1. Write a Class Date that takes day, month, and year while creating an object of this class. Find a new datewhen the number of days is given.2. Write a program to implement Boolean AND, OR, XOR, and NOT operations.3. Write…

  • Data types

    import java.util.Scanner; class A { public static void main(String args[]) { int a; char b; double d; long e; byte f; boolean g; String h; a=10; b=’e’; d=23.1; e=44; f=11; g=true; h=”aaa”; System.out.println(a); System.out.println(b); System.out.println(d); System.out.println(e); System.out.println(f); System.out.println(g); System.out.println(h); } }

  • Input Double

    import java.util.Scanner; class A { public static void main(String args[]) { double d; System.out.println(“Enter a Number”); Scanner inp=new Scanner(System.in); d=inp.nextDouble(); System.out.println(d); } }

  • Hello World

    class A { public static void main(String args[]) { System.out.println(“Hello World”);   } }