Category: Java programs

python tutorials and learn python

Created with Sketch.

Armstrong number in Java

  Armstrong number in Java Java program to check if a number is Armstrong or not, it is a number that is equal to the sum of digits raise to the power total number of digits in the number. Some of them are: 0, 1, 4, 5, 9, 153, 371, 407, 8208. Armstrong number program…
Read more

Floyd’s triangle in Java

  Floyd’s triangle in Java Java program to display Floyd’s triangle, in the triangle, there are n integers in the nth row and a total of (n(n+1))/2 integers in n rows. It is a simple pattern to print but helpful in learning how to create other patterns. The key to develop patterns is using nested…
Read more

Reverse a string in Java

  Reverse a string in Java Java program to reverse a string that a user inputs. The charAt method is used to get individual characters from the string, and we append them in reverse order. Unfortunately, there is no built-in method in the “String” class for string reversal, but it’s quite easy to create one.…
Read more

Palindrome in Java

  Palindrome in Java Java program to check if a string is a palindrome or not, a string is a palindrome if it remains the same on reversal. For example, “dad” is a palindrome, as its reverse is “dad,” whereas “program” isn’t, as its reverse is “margorp” that is different from “program.” Some palindrome strings…
Read more

Interface in Java

  Interface in Java Interface in Java: Java interfaces are like Java classes, but they contain only static final constants and declaration of methods. Methods are not defined, and classes that implement an interface must define the body of the method(s) of the interface(s). Final constants can’t change after we initialize them. The final, interface,…
Read more

Java program to compare two strings

  Java program to compare two strings How to compare two strings in Java, i.e., test whether they are equal or not? The compareTo method of String class is used to test the equality of its two objects. The method is case sensitive, i.e., “java” and “Java” are two different strings for it. If you…
Read more

Linear search in Java

  Linear search in Java Java program for linear search: Linear search is straightforward; to check if an element is present in the given list, we compare it with every element in the list. If it’s present, then we print the location at which it occurs; otherwise, the list doesn’t contain the element. Linear search…
Read more

Binary search in Java

  Binary search in Java Java program for binary search: This code implements the binary search algorithm. Please note that input numbers must be in ascending order. If they are not, you must sort them first. Binary search Java program import java.util.Scanner; class BinarySearch { public static void main(String args[]) { int c, first, last,…
Read more

Java program to find all substrings of a string

  Java program to find all substrings of a string Java program to find substrings of a string: This program finds all substrings of a string and then prints them. For example, substrings of “fun” are: “f”, “fu”, “fun”, “u”, “un” and “n”. The substring method of String class is used to find a substring.…
Read more

Java program to print date and time

  Java program to print date and time Java date and time program: Java code to print or display the current system date and time. We are using the GregorianCalendar class in our program. Don’t use Date and Time classes of java.util package as their methods are deprecated, i.e., they may not work in the…
Read more