Modi Coders

Modi Coders

  • Instagram
  • Facebook
  • Twitter
  • Blog
  • Contact
  • Java program to count the frequency of each vowel in a given string.

    August 2, 2024
    Java

    import java.util.Scanner; public class VowelFrequencyCounter { public static void main(String[] args) { // Create a Scanner object to read input from the user Scanner scanner = new Scanner(System.in); // Prompt the user to enter a string System.out.print(“Enter a string: “); String input = scanner.nextLine(); // Call the method to count vowels int[] vowelCounts = countVowels(input);…

  • Java program to swap two items belonging to an object using returning of object by a function.

    August 2, 2024
    Java

    class ItemPair { private int item1; private int item2; // Constructor to initialize the items public ItemPair(int item1, int item2) { this.item1 = item1; this.item2 = item2; } // Method to display the items public void display() { System.out.println(“Item 1: ” + item1 + “, Item 2: ” + item2); } // Method to swap…

  • Java program to demonstrate static variables, methods and blocks.

    August 2, 2024
    Java

    public class StaticDemo { // Static variable static int staticCounter = 0; // Instance variable int instanceCounter = 0; // Static block static { System.out.println(“Static block executed”); // Initialize static variable staticCounter = 10; } // Instance block { System.out.println(“Instance block executed”); // Initialize instance variable instanceCounter = 5; } // Static method static void…

  • Java program to implement grow able and shrinkable Stack that can support operations like– push, pop, and view the top item with concept of dynamic allocation using finalize() method. The program should also incorporate the concepts of private and public access methods to avoid accidental manipulations of stack.

    August 2, 2024
    Java

    class Stack { private int[] stackArray; private int top; private static final int INITIAL_CAPACITY = 10; // Constructor public Stack() { stackArray = new int[INITIAL_CAPACITY]; top = -1; } // Push an item onto the stack public void push(int value) { if (top == stackArray.length – 1) { grow(); } stackArray[++top] = value; } //…

  • Java program to find the area of rectangle using an abstract super class figure and also override method use to compute the area of the rectangle.

    August 2, 2024
    Java

    abstract class Figure { double length; double width; // Constructor public Figure(double length, double width) { this.length = length; this.width = width; } // Abstract method to compute the area abstract double computeArea(); } class Rectangle extends Figure { // Constructor public Rectangle(double length, double width) { super(length, width); } // Override method to compute…

  • Java program to find the area of all types of triangles using the principle of constructor overloading and Inheritance depending on the number of dimensions given in the input parameter list using super to call the super class constructor.

    August 2, 2024
    Java

    class Triangle { double base, height, side1, side2, side3; // Constructor for Equilateral Triangle public Triangle(double side) { this.side1 = this.side2 = this.side3 = side; } // Constructor for Isosceles Triangle public Triangle(double base, double height) { this.base = base; this.height = height; } // Constructor for Scalene Triangle public Triangle(double side1, double side2, double…

  • Java program to store and then prints sorted names of students according to their length of name using arrays with variable sized rows.

    August 2, 2024
    Java

    import java.util.Scanner; public class StudentNamesSorter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Get the number of students System.out.print(“Enter the number of students: “); int numberOfStudents = scanner.nextInt(); scanner.nextLine(); // Consume the newline // Array to store student names String[][] studentNames = new String[numberOfStudents][]; // Get student names from the…

  • Java Program to Add, Subtract, Multiply two matrices using switch statement. The program must also validate the sizes of two matrices before performing any operation and should raise exception in case the operation cannot be performed.

    August 2, 2024
    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.

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

    August 2, 2024
    Java

    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…

  • Write a Class Date that takes day, month, and year while creating an object of this class. Find a new date when the number of days is given.

    August 2, 2024
    Java

    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 =…

Previous Page
1 … 6 7 8 9
Next Page
  • Instagram
  • Facebook
  • Twitter

Modi Coders