Java Articles

Page 7 of 450

Java Program to Print Hollow Right Triangle Star Pattern

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 5K+ Views

In this article, we will understand how to print hollow right triangle star pattern. The pattern is formed by using multiple for-loops and print statements. For the pyramid at the first line it will print one star, and at the last line it will print n number of stars. For other lines it will print exactly two stars at the start and end of the line, and there will be some blank spaces between these two starts.Below is a demonstration of the same −InputSuppose our input is −Enter the size : 8OutputThe desired output would be −The hollow pyramid triangle ...

Read More

Java Program to Print Half Diamond Star Pattern

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

In this article, we will understand how to print half diamond star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −The half diamond pattern : * ** *** **** ***** ****** ******* ******** ******* ****** ***** **** *** ** *AlgorithmStep 1 - START Step 2 - Declare three integer values namely i, j and my_input Step 3 - Read the required values from the user/ define the values Step 4 - We iterate through two ...

Read More

Check if a string contains a number using Java.

Anjana
Anjana
Updated on 11-Mar-2026 41K+ Views

To find whether a given string contains a number, convert it to a character array and find whether each character in the array is a digit using the isDigit() method of the Character class.Examplepublic class ContainsExample {    public static void main(String args[]){       String sample = "krishna64";       char[] chars = sample.toCharArray();       StringBuilder sb = new StringBuilder();       for(char c : chars){          if(Character.isDigit(c)){             sb.append(c);          }       }       System.out.println(sb);    } }Output64

Read More

Java Program to Print Square Star Pattern

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 12K+ Views

In this article, we will understand how to print square star pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the length of a side : 8OutputThe desired output would be −The square pattern : * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ...

Read More

Java Program to Print an Integer

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 7K+ Views

In this article, we will understand how to print an integer in Java. It uses the int data type. The int data type is a 32-bit signed two's complement integer. The Minimum value is 2, 147, 483, 648 (-2^31) and the Maximum 2, 147, 483, 647(inclusive) (2^31 -1). Integer is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.InputSuppose our input isEnter an integer: 45OutputThe desired output would beThe integer is: 45AlgorithmStep 1- START Step 2- Prompt the user to enter an integer value/ define the integer ...

Read More

Constructor overloading in Java

Sravani S
Sravani S
Updated on 11-Mar-2026 7K+ Views

Yes! Java supports constructor overloading. In constructor loading, we create multiple constructors with the same name but with different parameters types or with different no of parameters.Examplepublic class Tester {      private String message;      public Tester(){       message = "Hello World!";    }    public Tester(String message){       this.message = message;    }      public String getMessage(){       return message ;    }      public void setMessage(String message){       this.message = message;    }      public static void main(String[] args) {       Tester tester = new Tester();       System.out.println(tester.getMessage());           Tester tester1 = new Tester("Welcome");       System.out.println(tester1.getMessage());      } }   OutputHello World! Welcome

Read More

Java Program to Add Two Binary Strings

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

In this article, we will understand how to add two binary strings in Java. A binary string is a sequence of numbers represented in bytes 0s and 1s.Below is a demonstration of the same −InputSuppose our input is −10101 10001OutputThe desired output would be −100110 AlgorithmStep 1- START Step 2- Create new scanner object Step 3- Enter two binary inputs Step 4- Define a carry flag Step 5- Use while condition to check if they are equal to 0 Step 6- If not, use the % operator and the carry flag to perform bitwise addition Step 7-Display it as result ...

Read More

Java Program to Print a String

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 17K+ Views

In this article, we will understand how to print a string in Java. A string is a pattern of characters and alphanumeric values. The easiest way to create a string is to write −String str = "Welcome to the club!!!"Whenever it encounters a string literal in your code, the Java compiler creates a String object with its value in this case, " Welcome to the club!!!'.As with any other object, you can create String objects by using the new keyword and a constructor. The String class has 11 constructors that allow you to provide the initial value of the string ...

Read More

Java Program to Find Even Sum of Fibonacci Series till number N

Manisha Chand
Manisha Chand
Updated on 11-Mar-2026 3K+ Views

In this article, we will learn how to find the even sum of the Fibonacci series up to a given number N. A Fibonacci series is a series where the next term is the sum of the previous two terms. An even Fibonacci series is a group of all the even numbers in the Fibonacci series. The first two terms of the Fibonacci sequence are 0 and 1. Fn = Fn-1 + Fn-2 Hence, a Fibonacci series can look like this - F8 = 0 1 1 2 3 5 8 13 or, this F8 = 1 1 2 3 5 ...

Read More

Java program to calculate the compound interest

Manisha Chand
Manisha Chand
Updated on 11-Mar-2026 16K+ Views

In this article, we will understand how to calculate compound interest in Java. Compound interest is calculated using the following formula. Amount = P(1 + R/100)t Compound Interest = Amount - Principle where, P is the principal amount T is the time R is the rate Compound interest is the interest calculated on the initial principal and also on the accumulated interest of previous periods. In other words, Compound Interest = Interest on Principal + Interest on Interest. We'll learn how to get user input for the principal amount, interest rate, and time period, and then calculate the compound interest based ...

Read More
Showing 61–70 of 4,496 articles
« Prev 1 5 6 7 8 9 450 Next »
Advertisements