Java Program to find Armstrong numbers with Example

Armstrong number Example in Java
How to check if a number is an Armstrong number or not? or write a Java program to find Armstrong's number? This is a common Java interview question asked on-campus interviews and fresher-level interviews. This is also a popular Java programming exercise on various schools, colleges, and computer courses to build programming logic among Students. An Armstrong number is a 3 digit number for which the sum of cube of its digits is equal to the number itself. 

How to check if Array contains given Number or String in Java [ Linear Search vs Binary Search]

Hello guys, one of the common coding questions from Java interviews is how to test if an Array contains a certain value or not? This is a simple question, but sometimes interview pressure makes candidates nervous. In this article, you'll learn how to solve this problem using different approaches. Since an array in Java doesn't have any inbuilt method for searching values, interviewers prefer to ask this question, to see how a candidate deals with such a situation. If you have good knowledge of Java API, then you will immediately come to know that there are alternatives available like using the binarySearch() method of Java Java .util.Arrays class or taking advantage of ArrayList contains method by first converting your array to ArrayList.

Review - Is AlgoMonster.com Good Place for Coding and System Design Interview Preparation in 2025?

Hello guys, if you are preparing for coding interviews and wondering whether joining AlgoMonster is right decision or not then you have come to the right place. Earlier I have shared best website for coding interview preparation, books, and best coding interview courses and in this article, we will review Algo Monster, one of the top site for coding interview preparation. Before we review Algomonster, let me tell you what it really is. For those of you who don't know, Algomonster is a legit site and basically an interview prep site with a focus on coding that will help you clear your interview and land your dream coding job. 

[Solved] How to Print Alphabets in Upper and Lower Case in Java? Example Tutorial

Hello guys, if you are learning Java and looking for basic programming exercise to build your concepts then you have come to the right place. Earlier, I have shared 15 common Java programming exercises and today, you will learn one of them. One of the textbook exercises to get started with any programming language is writing a program to print alphabets in both upper and lower case. This program allows you to explore the String class in Java with the toUpperCase() and toLowerCase() method but normally when you start, it's asked to do this without any API methods.

How to Print Pyramid Pattern in Java? Program Example

Pattern based exercises are a good way to learn nested loops in Java. There are many pattern based exercises and one of them is printing Pyramid structure as shown below:


* * 
* * * 
* * * * 
* * * * * 

You need to write a Java program to print the above pyramid pattern. How many levels the pyramid triangle would have will be decided by the user input. You can print this kind of pattern by using print() and println() method from System.out object. System.out.print() just prints the String or character you passed to it, without adding a new line, useful to print stars in the same line. 

How to Print Prime Numbers from 1 to 100 in Java [Solved]

Hello guys, today, I'll share with you a simple problem of writing a Java program to print prime numbers up to a given number like saying prime numbers from 1 to 100. It's one of the most common coding exercises for programmers learning in Java, as it gives you an opportunity to learn more about the essential operators in Java Programming. The key here is that you cannot use a library function which can simplify your job, you need to devise the algorithm for checking prime number by yourself. One of the most popular algorithms for generating prime is Sieve of Eratosthenes,  which we have discussed earlier, but in this post, we will take a simpler approach.

How to calculate sum and difference of two complex numbers in Java? Example

From the last couple of articles, I am writing about coding exercises for beginners e.g. yesterday you learned how to write a program from matrix multiplication in Java (see here) and a couple of days back, you have learned the recursive binary search algorithm. To continue that tradition today I am going to show you how to write a program for calculating the sum and difference of two complex numbers in Java. If you remember the complex number from you Maths classes, it has two-part real and imaginary and to add a complex number we add their real and imaginary part separately, similar to subtract complex number we minus their real and imaginary part separately. 

How to Find Duplicate Characters in String [Java Coding Problems]

Hello guys, today's programming exercise is to write a program to find repeated characters in a String. For example, if given input to your program is "Java", it should print all duplicates characters, i.e. characters appear more than once in String and their count like a = 2 because of character 'a' has appeared twice in String "Java". This is also a very popular coding question on the various level of Java interviews and written tests, where you need to write code. On the difficulty level, this question is at par with the prime numbers or Fibonacci series, which are also very popular on junior level Java programming interviews and it's expected from every programmer to know how to solve them.

Write a Program to Find Sum of Digits in Java

One of the common programming practice question thrown to beginners is to write a program to calculate the sum of digits in an integral number. For example, if the input is 123456 then output or sum of the digit is (1+2+3+4+5+6) = 21. An additional condition is you can not use any third party or library method to solve this problem. This program is not as simple as it looks and that's why it's a good exercise, you must know some basic programming techniques e.g. loops, operators, and logic formation to solve this problem. Let's see how we can solve this problem using Java programming language. In order to calculate the sum of digits, we must get digits as numbers. So your first challenge is how do you get the digits as numbers?  How do we extract 6 out of 123456?

How to calculate perimeter and area of square in Java? Example Tutorial

If you are looking for a solution of problem how to calculate perimeter and area of a given Square in Java then you have come at the right place. In this article, I have given step by step solution of this common coding problem. This was actually a homework exercise when I was learning Java program and since I was good at Maths, I know how to calculate Perimeter and Area of Circle and Square but big challenge for me was to convert that knowledge into code. Another big challenge for me was how to take input from user actually that was the mistake I made when I first solved this problem. 

How to calculate Compound Interest in Java? Compound Interest Calculator in Java Example Tutorial

Hello guys, if you are wondering how to calculate compound interest in Java or looking for Java program to calculate compound interest then you have come at the right place. Earlier I have shared how to calculate simple interest in Java and today I am going to share how to calculate compound interest in Java program. Calculating simple interest or compound interest are common coding problem which are taught in schools and colleges to teach you coding. The best thing about these coding exercise in Java are that everybody are familiar with them so you know the concept already and all you need to do is convert that solution into code which is the skill needed to become a coder or programmer.