This is a java program for happy number but before that what is a happy number. A number whose sum of the square of digits is ultimatly equal to 1 is a happy number. By ultimately we mean that starting with any positive number we continue the addition of square of digits till we get a single digit number (0 ...

Read More »## Java program for reversing a number

This program reverses a number given as a input. This java program for reversing a number uses a concept of dividing the given number by 10 and adding the remainder to the units digit in new number everytime. You can add to a unit place everytime by multiplying a number by 10 first(which will leave unit digit as 0) and ...

Read More »## Java Program to check for a Kaprekar number

Here is given java program to check for a Kaprekar number. But before what exactly is a Kaprekar number and why it is called a kaprekar number? A Kaprekar number is a number whose square can be broken/partitioned in such a manner that the sum of the partitions adds up to bring the number itself. Example: 992 = 9801 : 98+01 ...

Read More »## Bluej/Java program for spiral matrix

This is a java program for spiral matrix. import java.util.*; //for importing scanner class class spiral { public static void main(String args[]) { Scanner obj=new Scanner(System.in); //can also be done by BufferReader. But then use: import.java.io.*; System.out.print("\nEnter the size of matrix (nxn):"); int n=obj.nextInt(); int a[][]=new int[n][n]; System.out.println("Your matrix is of order "+n+"x"+n+"\n"); int d,c,i,j,l,t,m,k; d=n-1; c=n*n+1; // if its ...

Read More »## Java Program to check for a Magic Number

This is a Java program for Magic number. However before starting let me tell you what is a magic number. A Magic number is a number whose sum of digits eventually leads to 1. Example#1: 19 ; 1+9 =10 ; 1+0 = 1. Hence a magic number. Example#2: 226; 2+2+6=10; 1+0 =1. Hence a magic number. Example#3: 874; 8+7+4=19; 1+9=10; 1+0=1. ...

Read More »## Program for smith number in Java

This is a program in java to check whether a number is a or not. import java.io.*; class smithnumber { static int sumdigit(int x) //to find the sum of digits { int sum=0; if(x!=0) sum+=x%10+sumdigit(x/10); return sum; } static int sumfact(int x) { int i,fact=0; for(i=2;i<=x;i++) { if(prime(i)) { while(x%i==0) { fact+=sumdigit(i); x/=i; } } } return fact; } static ...

Read More »## Java program to translate english to piglatin form

This is a program to convert a english word into piglatin form: Piglatin form: Any word is converted into piglatin form by starting the word from the first vowel and adding the remaining part in the end followed by “AY” import java.io.*; class piglatin { public static void main(String args[])throws Exception { String a; char c;int i,l; System.out.println("Enter a word"); ...

Read More »## Program in Java to find whether a number is perfect or not

Perfect Number- If the sum of all the factors of a number is equal to the number itself then it is a perfect number. This program finds whether a given number is perfect number or not. Example:- 6 = 1+2+3 28 = 1+2+4+7+14

Read More »