 ### In this post, we will discuss some basic and simple number programs in java .

for more java programs
https://java4school.com/double-dimensional-arraymatrix-programs-part-i

1. A program to calculate GCD(greatest common divisor) of two numbers:-

The greatest common divisor (gcd) of two or more integers, is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4.

import java.util.*;
class gcd{
public static void main(){
Scanner sc=new Scanner(System.in);
System.out.println(“Enter 2 numbers:”);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(“\n ****Calculating GCD****\n”);
int t=0;
if(a>b){
t=a;
a=b;
b=t;
}
if(a==0){
System.out.println(“GCD:”+a);
b=0;
}
while(b!=0){
t=0;
if(b%a==0){
System.out.println(“GCD:”+a);
break;
}
else{
t=b%a;
b=a;
a=t;
}
}
}
}

output:-

Enter 2 numbers

12 8

****Calculating GCD****

GCD 4

2. Automorphic  Number:-

An automorphic number is a number whose square “ends” in the same digits as the number itself. For example, 52 = 25, 62 = 36

import java.util.*;
class automorphic{
public static void main(){
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number:”);
int n=sc.nextInt();
double sq=Math.pow(n,2);
int t=n,c=0,d=0;
while(t>0){
d=t%10;
c=c+1;;
t/=10;
}
double s=Math.pow(10,c);
int r=(int)sq%(int)s;
if(r==n){
System.out.println(“It is automorphic.”);
}
else{
System.out.println(“Not automorphic.”);
}
}
}

For videos related to java programming