Blog

python tutorials and learn python

Created with Sketch.

Java Program to Concatenate Two Arrays

Java Program to Concatenate Two Arrays In this program, you’ll learn to concatenate two arrays in Java using arraycopy and without it.   Example 1: Concatenate Two Arrays using arraycopy import java.util.Arrays; public class Concat { public static void main(String[] args) { int[] array1 = {1, 2, 3}; int[] array2 = {4, 5, 6}; int…
Read more

Java Program to Round a Number to n Decimal Places

Java Program to Round a Number to n Decimal Places In this program, you’ll learn to round a given number to n decimal places in Java. Example 1: Round a Number using format public class Decimal { public static void main(String[] args) { double num = 1.34567; System.out.format(“%.4f”, num); } } When you run the…
Read more

Java Program to Convert String to Date

Java Program to Convert String to Date In this program, you’ll learn to convert string to date in Java using formatter. Example 1: Convert String to Date using predefined formatters import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class TimeString { public static void main(String[] args) { // Format y-M-d or yyyy-MM-d String string = “2017-07-25”; LocalDate date…
Read more

Java Program to Print an Array

Java Program to Print an Array In this program, you’ll learn different techniques to print the elements of a given array in Java. Example 1: Print an Array using For loop public class Array { public static void main(String[] args) { int[] array = {1, 2, 3, 4, 5}; for (int element: array) { System.out.println(element);…
Read more

Java Program to Remove All Whitespaces from a String

Java Program to Remove All Whitespaces from a String In this program, you’ll learn to remove all whitespaces in a given string using regular expressions in Java. Example: Program to Remove All Whitespaces public class Whitespaces { public static void main(String[] args) { String sentence = “T his is b ett er.”; System.out.println(“Original sentence: “…
Read more

Java Code To Create Pyramid and Pattern

Java Code To Create Pyramid and Pattern In this program, you’ll learn to create pyramid, half pyramid, inverted pyramid, Pascal’s triangle and Floyd’s triangle sing control statements in Java. Programs to print triangles using *, numbers and characters Example 1: Program to print half pyramid using * * * * * * * * *…
Read more

Java Program to Calculate Difference Between Two Time Periods

Java Program: Calculate Difference Between Two Time Periods In this blog post, we’ll explore a Java program that calculates the difference between two time periods. The program takes two time values as input, representing the start and end times, and computes the duration between them. We will provide a step-by-step explanation of the algorithm, showcase…
Read more

Java Program to Add Two Complex Numbers by Passing Class to a Function

Java Program to Add Two Complex Numbers by Passing Class to a Function In this program, you’ll learn to add two complex numbers in Java by creating a class named Complex and passing it into a function add(). Example: Add Two Complex Numbers public class Complex { double real; double imag; public Complex(double real, double…
Read more

Java Program to Sort Elements in Lexicographical Order (Dictionary Order)

Java Program to Sort Elements in Lexicographical Order (Dictionary Order) In this program, you’ll learn to sort the element words in lexicographical order using a for loop and if else in Java. Example: Program to Sort Strings in Dictionary Order public class Sort { public static void main(String[] args) { String[] words = { “Ruby”,…
Read more

Java Program to Count the Number of Vowels and Consonants in a Sentence

Java Program to Count the Number of Vowels and Consonants in a Sentence In this program, you’ll learn to count the number of vowels, consonants, digits and spaces in a given sentence using if else in Java. Example: Program to count vowels, consonants, digits and spaces public class Count { public static void main(String[] args)…
Read more