Create a method area(),overload it to calculate area of circle ,rectangle and square.

JAVA-17 Q.17 Create a method area(),overload it to calculate area of circle ,rectangle and square. Solution :-  class Shape { // Method to calculate area of a circle double area(double radius) { return Math.PI * radius * radius; } // Method to calculate area of a rectangle double area(double length, double breadth) { return length […]

WAJP to create a Player class.Inherit the classes Cricket_Player,Football_Player and Hockey_ Player from Player class.

JAVA-15 Q.15 WAJP to create a Player class.Inherit the classes Cricket_Player,Football_Player and Hockey_ Playerfrom Player class.   class Player { protected String name; protected int age; public Player(String name, int age) { this.name = name; this.age = age; } public void display() { System.out.println(“Name: ” + name); System.out.println(“Age: ” + age); } } class Cricket_Player […]

Write an application that creates and start three threads, each thread is instantiated from the same class. It executes a loop with 5 iterations. First thread display “BEST”, second thread display “OF” and last thread display “LUCK”. All threads sleep for 1000 ms. The application waits for all threads to complete and display a message.

JAVA-13 Q.13 Write an application that creates and start three threads, each thread is instantiated from the sameclass. It executes a loop with 5 iterations. First thread display “BEST”, second thread display “OF” andlast thread display “LUCK”. All threads sleep for 1000 ms. The application waits for all threads tocomplete and display a message. Solution […]

Write a Java program to display string with capital letters which are inputted through command line. Display those string(s) which starts with “B”.

JAVA-13 Q.13 Write a Java program to display string with capital letters which are inputted through command line. Display those string(s) which starts with “B”. Solution  :-  public class DisplayStringsStartingWithB { public static void main(String[] args) { if (args.length == 0) { System.out.println(“Please provide input strings as command-line arguments.”); return; } System.out.println(“Strings starting with ‘B’:”); […]

Write a Java code that handles the custom exception like when a user gives input as Floating point number then it raises exception with appropriate message.

JAVA-12 Q.12 Write a Java code that handles the custom exception like when a user gives input as Floating point number then it raises exception with appropriate message. Solution  :-  import java.util.*; // Custom exception class class FloatingPointInputException extends Exception { public FloatingPointInputException(String message) { super(message); } } public class CustomExceptionExample { public static void […]

Create class EMPLOYEE in java with id, name and salary as data-members. Again create 5 different employee objects by taking input from user. Display all the information of an employee which is having maximum salary.

JAVA-11 Q.11 Create class EMPLOYEE in java with id, name and salary as data-members. Again create 5 different employee objects by taking input from user. Display all the information of an employee which is having maximum salary. Solution :-  import java.util.*; class Employee { int id; String name; double salary; public Employee(int id, String name, […]

Write a Java program that prompts the user to input the base and height of a triangle. Accordingly calculates and displays the area of a triangle using the formula (base* height) / 2, and handles any input errors such as non-numeric inputs or negative values for base or height. Additionally, include error messages for invalid input and provide the user with the option to input another set of values or exit the program.

JAVA-9 Q.9 Write a Java program that prompts the user to input the base and height of a triangle. Accordingly calculates and displays the area of a triangle using the formula (base* height) / 2, and handles any input errors such as non-numeric inputs or negative values for base or height. Additionally, include error messages […]

Write a java application which accepts two strings. Merge both the strings using alternate characters of each one. 

JAVA-8 Q.8 Write a java application which accepts two strings. Merge both the strings using alternate characters of each one.  Solution :-  import java.util.*; public class MergeStrings { public static String mergeAlternate(String str1, String str2) { StringBuilder merged = new StringBuilder(); int length1 = str1.length(), length2 = str2.length(); int maxLength = Math.max(length1, length2); for (int […]

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.