Blog

python tutorials and learn python

Created with Sketch.

Using multiple classes in a Java program

  Using multiple classes in a Java program A Java program may contain any number of classes. The following program comprises of two classes: Computer and Laptop, both the classes have their constructors and a method. In the main method, we create objects of two classes and call their methods. Using two classes in Java…
Read more

Java constructor

  Java constructor A Java constructor is a method that is used to initialize an object. It has the same name as that of the class and is called or invoked when we create an object of the class, and we can’t call them explicitly. While creating an object, its attributes may or may not…
Read more

Exception handling in Java

  Exception handling in Java Java exception handling: we learn how to handle exceptions in Java with the help of suitable examples. Exceptions are errors that occur when a program executes. At compile time, syntax and semantics checking is done, and code doesn’t get executed on a machine, so exceptions get caught at run time.…
Read more

Swapping of two numbers in Java

  Swapping of two numbers in Java Java program to swap two numbers with and without using an extra variable. Swapping is frequently used in sorting techniques such as bubble sort, quick sort, and other algorithms. Swapping program in Java import java.util.Scanner; class SwapNumbers { public static void main(String args[]) { int x, y, t;…
Read more

Java program to find the largest of three numbers

  Java program to find the largest of three numbers Java program to find the largest of three numbers, if the numbers are unequal, then “numbers are not distinct” is printed. Comparison operator ‘>’ is used to compare two numbers. To find the largest number out of given numbers you can also use an array.…
Read more

Enhanced for loop in Java

  Enhanced for loop in Java Enhanced for loop in Java is better when scanning a complete array instead of using a for loop. Its syntax is: for (data_type variable: array_name) Here, array_name is the name of an array. Enhanced for loop Java program class EnhancedForLoop { public static void main(String[] args) { int primes[]…
Read more

Factorial Program in Java

  Factorial Program in Java Java program to find factorial of a number, if the number is negative, then an error message is printed. You can also find factorial using recursion. The first program uses integer data type so it can calculate the factorial of small numbers only. Factorial of large numbers using BigInteger. Factorial…
Read more

Java program to print prime numbers

  Java program to print prime numbers Java program to print prime numbers, a user input how many of them are required. Remember, the smallest prime number is 2. We use the sqrt method of Math package, which finds the square root of a number. To check if an integer (say n) is prime, you…
Read more

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