Mindblown: a blog about philosophy.
-
Implement private constructors
Java program to create a private constructor Output In the above example, we have created a private constructor of the Test class. Hence, we cannot create an object of the Test class outside of the class. This is why we have created a public static method named instanceMethod() inside the class that is used to create an object of the Test class. And from the Main class,…
-
Determine the class of an object
Check the class of an object using getClass() Output In the above example, we have used the getClass() method of the Object class to get the class name of the objects obj1 and obj2.
-
Program to perform binary search
Example Program to perform binary search on a list of integer numbers This program uses binary search algorithm to search an element in given list of elements. Output 1: Output 2:
-
Program for linear search – Example
Example Program: This program uses linear search algorithm to find out a number among all other numbers entered by user. Output 1: Output 2:
-
Bubble sort in Ascending and descending order
in this tutorial we are gonna see how to do sorting in ascending & descending order using Bubble sort algorithm. Bubble sort program for sorting in ascending Order Output: Bubble sort program for sorting in descending Order In order to sort in descending order we just need to change the logic array[j] > array[j+1] to array[j] <…
-
Program to calculate area and circumference of circle
In this tutorial we will see how to calculate area and circumference of circle in Java. There are two ways to do this: 1) With user interaction: Program will prompt user to enter the radius of the circle2) Without user interaction: The radius value would be specified in the program itself. Program 1: Output: Program 2:…
-
Program to calculate area of Triangle
Here we will see how to calculate area of triangle. We will see two following programs to do this:1) Program 1: Prompt user for base-width and height of triangle.2) Program 2: No user interaction: Width and height are specified in the program itself. Program 1: Output: Program 2: Output:
-
Program to calculate area of Square
In this tutorial we will learn how to calculate area of Square. Following are the two ways to do it: 1) Program 1: Prompting user for entering the side of the square2) Program 2: Side of the square is specified in the program’ s source code. Program 1: Output: Program 2: Output:
-
Program to Calculate Area of Rectangle
In this tutorial we will see how to calculate Area of Rectangle. Program 1:User would provide the length and width values during execution of the program and the area would be calculated based on the provided values. Output: Program 2:In the above program, user would be asked to provide the length and width values. If you…
-
Program to get input from user
In this tutorial we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:1) public String nextLine(): For getting input String2) public int nextInt(): For integer input3)…
Got any book recommendations?