- Number Based Programs in Java
- 5. Java Program to Check Armstrong Number
- 6. Java Program to Find GCD of Two Numbers
- 7. Java Program to Find Largest of Three Numbers
- 8. Java Program to Find Factorial of a Number
- 9. Java Program to Multiply Two Numbers
- 10. Java Program to find the Smallest of three numbers using Ternary Operator
- Related Java Programs
Number Based Programs in Java
Armstrong Number is a positive number if it is equal to the sum of cubes of its digits is called Armstrong number and if its sum is not equal to the number then its not a Armstrong number. Armstrong Number Program is very popular in java, c language, python etc. Examples: 153 is Armstrong, (1*1*1)+(5*5*5)+(3*3*3) = 153
Automorphic Number Program in Java
An Automorphic number is a number whose square “ends” in the same digits as the number itself. Examples: 5*5 = 25, 6*6 = 36, 25*25 = 625
Buzz Number Program in Java
A number is said to be Buzz Number if it ends with 7 or is divisible by 7. Example: 1007 is a Buzz Number.
Circular Prime Program in Java
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its digits will be prime. For example, 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime.
CoPrime Numbers Program in Java
Two integers a and b are said to be relatively prime, mutually prime, or coprime if the only positive integer that divides both of them is 1. Example: 13 and 15 are co prime.
Digit to Word Program in Java
Duck Number Program in Java
A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210
Factorial Program in Java
A Duck number is a number which has zeroes present in it, but there should be no zero present in the beginning of the number. For example 3210
Factors Program in Java
Factor a number or algebraic expression that divides another number or expression evenly—i.e., with no remainder. For example, 3 and 6 are factors of 12 because 12 ÷ 3 = 4 exactly and 12 ÷ 6 = 2 exactly. The other factors of 12 are 1, 2, 4, and 12. Factors of 12: 1, 2, 3, 4, 6, 8, 12.
Fibonacci Series Program in Java
A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 0, 1, 1, 2, 3, 5, 8, etc.
Floyd Triangle Program in Java
Floyd Triangle Program in Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Greatest Common Divisor Program in Java
the greatest common divisor (gcd) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4.
Happy Number Program in Java
A happy number is a natural number in a given number base that eventually reaches 1 when iterated over the perfect digital invariant function for. Those numbers that do not end in 1 are -unhappy numbers.
Harshad Number Program in Java
In mathematics, a harshad number (or Niven number) in a given number base is an integer that is divisible by the sum of its digits when written in that base.
Least Common Multiple Program in Java
The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.
Multiply Of Digit Program in Java
If a number=1234, then 1*2*3*4 ,Multiply of digit=24, Multiply Of Digit Program in Java
Neon Number Program in Java
A neon number is a number where the sum of digits of square of the number is equal to the number. For example if the input number is 9, its square is 9*9 = 81 and sum of the digits is 9. i.e. 9 is a neon number.
Niven Number Program in Java
In mathematics, a Niven number (or harshad number) in a given number base is an integer that is divisible by the sum of its digits when written in that base.
Palindrome Number Program in Java
A palindromic number is a number that remains the same when its digits are reversed. Like 16461, for example,
Perfect Number Program in Java
A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3, and 1 + 2 + 3 = 6, so 6 is a perfect number.
Prime Number Program in Java
A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself.
Reverse Number Program in Java
If a number=1234, then reverse of number is 4321.
Special Number Program in Java
A number is said to be special number when the sum of factorial of its digits is equal to the number itself. Example- 145 is a Special Number as 1!+4!+5!=145.
Spy Number Program in Java
A spy number is a number where the sum of its digits equals the product of its digits. For example, 1124 is a spy number, the sum of its digits is 1+1+2+4=8 and the product of its digits is 1*1*2*4=8.
Twin Prime Program in Java
A twin prime is a prime number that is either 2 less or 2 more than another prime number—for example, either member of the twin prime pair (41, 43). In other words, a twin prime is a prime that has a prime gap of two.
Twisted Prime Program in Java
A number is called a twisted prime number if it is a prime number and reverse of this number is also a prime number.
Unique Number Program in Java
A number is said to be unique , if the digits in it are not repeated. for example, 12345 is a unique number. 123445 is not a unique number.
Disarium Number Program in Java
A number is called Disarium number if the sum of its power of the positions from left to right is equal to the number. Example: 1 + 3*3 + 5*5*5 = 1 + 9 + 125 = 135
Tech Number Program in Java
A tech number can be tech number if its digits are even and the number of digits split into two number from middle then add these number if the added number’s square would be the same with the number it will called a Tech Number. If the number is split in two equal halves,then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers. Note: If number of digits is not even then it is not a tech number.
Prime Number Up to N Terms Program in Java
Prime Number Up to N Terms Program in Java. Ex: Enter size of prime=5 Number is prime=2 Number is prime=3 Number is prime=5 Number is prime=7 Number is prime=11 Number is prime=13
Magic Number Program in Java
Magic number is the if the sum of its digits recursively are calculated till a single digit If the single digit is 1 then the number is a magic number. Magic number is very similar with Happy Number.
Pronic Number Program in Java
A number is said to be a pronic number if product of two consecutive integers is equal to the number, is called a pronic number. Example- 42 is said to be a pronic number, 42=6×7, here 6 and 7 are consecutive integers
Ugly Number Program in Java
A number is said to be an Ugly number if positive numbers whose prime factors only include 2, 3, 5. For example, 6(2×3), 8(2x2x2), 15(3×5) are ugly numbers while 14(2×7) is not ugly since it includes another prime factor 7. Note that 1 is typically treated as an ugly number.
5. Java Program to Check Armstrong Number
Armstrong Number in Java: A positive number is called Armstrong number if it is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.
153 = (1*1*1)+(5*5*5)+(3*3*3) where: (1*1*1)=1 (5*5*5)=125 (3*3*3)=27 So: 1+125+27=153
package com.javaguides.java.tutorial; import java.util.Scanner; /** * Java Program to Check Armstrong Number * * @author https://www.javaguides.net/ * */ public class JavaProgram < public static void main(String[] args) < try (Scanner scanner = new Scanner(System.in)) < int temp, total = 0; System.out.println("Ënter 3 Digit Number : "); int num = scanner.nextInt(); int number = num; for (; number != 0; number /= 10) < temp = number % 10; total = total + temp * temp * temp; > if (total == num) < System.out.println(num + " is an Armstrong number"); > else < System.out.println(num + " is not an Armstrong number"); > > > >
Ënter 3 Digit Number : 153 153 is an Armstrong number
6. Java Program to Find GCD of Two Numbers
package com.javaguides.java.tutorial; import java.util.Scanner; /** * Java Program to Find GCD of Two Numbers * * @author https://www.javaguides.net/ * */ public class JavaProgram < public static void main(String[] args) < try (Scanner scanner = new Scanner(System.in)) < int num1, num2; System.out.print("Enter first number:"); num1 = (int) scanner.nextInt(); System.out.print("Enter second number:"); num2 = (int) scanner.nextInt(); // closing the scanner to avoid memory leaks scanner.close(); while (num1 != num2) < if (num1 > num2) num1 = num1 - num2; else num2 = num2 - num1; > // displaying the result System.out.printf("GCD of given numbers is: %d", num2); > > >
Enter first number:10 Enter second number:20 GCD of given numbers is: 10
7. Java Program to Find Largest of Three Numbers
package com.javaguides.java.tutorial; import java.util.Scanner; /** * Java Program to find largest of three Numbers * * @author https://www.javaguides.net/ * */ public class JavaProgram < public static void main(String[] args) < try (Scanner scanner = new Scanner(System.in)) < int num1, num2, num3; System.out.print("Enter first number:"); num1 = (int) scanner.nextInt(); System.out.print("Enter first number:"); num2 = (int) scanner.nextInt(); System.out.print("Enter first number:"); num3 = (int) scanner.nextInt(); if (num1 >= num2 && num1 >= num3) < System.out.println(num1 + " is the largest Number"); > else if (num2 >= num1 && num2 >= num3) < System.out.println(num2 + " is the largest Number"); > else < System.out.println(num3 + " is the largest Number"); > > > >
Enter first number:50 Enter first number:20 Enter first number:60 60 is the largest Number
8. Java Program to Find Factorial of a Number
import java.math.BigInteger; import java.util.Scanner; public class FactorialExample < public static void main(String[] args) < Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int n = scanner.nextInt(); BigInteger fact = factorial(n); System.out.printf("%d! is %d", n, fact); scanner.close(); > private static BigInteger factorial(int value) < BigInteger result = BigInteger.ONE; if (value != 0 && value != 1) < for (int i = 2; i value; i++) < result = result.multiply(BigInteger.valueOf(i)); > > return result; > >
Enter a number: 5 5! is 120
9. Java Program to Multiply Two Numbers
package com.javaguides.java.tutorial; import java.util.Scanner; /** * Java Program to check Even or Odd number * * @author https://www.javaguides.net/ * */ public class JavaProgramMultiplyNumber < public static void main(String[] args) < try (Scanner sc = new Scanner(System.in)) < // Read number from user System.out.println("Enter Number: "); int number = sc.nextInt(); /* * If number is divisible by 2 then it's an even number else odd number */ if (number % 2 == 0) < System.out.println("The number " + number + " is even"); > else < System.out.println("The number " + number + " is odd"); > > > >
Enter first number: 10 Enter second number: 20 Output: 200
10. Java Program to find the Smallest of three numbers using Ternary Operator
package com.javaguides.java.tutorial; import java.util.Scanner; /** * Java Program to find the Smallest of three numbers using Ternary Operator * * @author https://www.javaguides.net/ * */ public class JavaProgram < public static void main(String[] args) < try (Scanner scanner = new Scanner(System.in)) < int num1, num2, num3, temp; System.out.print("Enter first number:"); num1 = (int) scanner.nextInt(); System.out.print("Enter Second number:"); num2 = (int) scanner.nextInt(); System.out.print("Enter Third number:"); num3 = (int) scanner.nextInt(); temp = num1 num2 ? num1 : num2; int result = num3 temp ? num3 : temp; System.out.println("Smallest Number is:" + result); > > >
Enter first number:10 Enter Second number:2 Enter Third number:3 Smallest Number is:2
Related Java Programs
- String Programs in Java with Output
- Java Program to Count Number of Duplicate Words in String
- Java Program to Count Number of Words in Given String
- Java Program to Count the Number of Occurrences of Substring in a String
- Java Program to Count the Occurrences of Each Character in String
- Java Program to Merge two String Arrays
- Java Program to Remove Duplicate Words from String
- Java Program to Reverse a String(5 ways)
- Java Program to Reverse Each Word of a String
- Java Program to Swap Two Strings
- How to Check if the String Contains only Digits
- How to Check if the String Contains only Letters
- How to Check If the String Contains Only Letters or Digits
- Java Program to Check if Input String is Palindrome
- Java Program to Find all Permutations of String
- How to Remove or Trim All White Spaces from a String in Java
- How to Remove Leading and Trailing White Space From a String in Java
- Java Program to Count Duplicate Characters in a String
- Remove Character from String in Java (Java 8)
- Java Program to Count Vowels and Consonants in a String (Java 8)
- 4 Ways to Find First Non-Repeated Character in String in Java