Computer Application (JAVA) Series and Number Based Programs
Computer Application (JAVA) Series and Number Based Programs
A day and night is 23 hours, 56 minutes and 4.1 seconds. It takes 365 days, 5 hours,
48 minutes and 45 seconds for the Earth to complete one round of the sun.
In easy terms, the year that the remaining zero is divided by 4 will be a leap year, but
only that century will be a leap year, which is completely divided by 400.
import java.util.Scanner;
Output:
Enter a year=1600
Not a leap year
Greatest Number Program in Java
import java.util.Scanner;
public class GreatestNumber {
public static void main(String[] args) {
int n1, n2, n3;
Scanner sc = new Scanner(System.in);
System.out.print("Enter n1 number=");
n1 = sc.nextInt();
System.out.print("Enter n2 number=");
n2 = sc.nextInt();
System.out.print("Enter n3 number=");
n3 = sc.nextInt();
Enter n1 number=15
Enter n2 number=18
Enter n3 number=10
n2 is greatest.
Even Odd Program in Java
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
int number;
Scanner sc = new Scanner(System.in);
if (number % 2 == 0) {
System.out.println("Number is even.");
} else {
System.out.println("Number is odd.");
}
}
}
Output:
(1*1*1)+(5*5*5)+(3*3*3) = 153
import java.util.Scanner;
/**
* @author AFAQ
*/
public class ArmstrongNumber
{
public static void main(String[] args)
{
int n,
cubeSum = 0, num, r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
cubeSum = cubeSum + (r * r * r);
num = num / 10;
}
if (n == cubeSum)
{
System.out.println("Armstrong Number");
}
else
{
System.out.println("Not Armstrong Number");
}
}
}
Output:
Enter number=153
Armstrong Number
Buzz Number Program in Java
import java.util.Scanner;
public class BuzzNumber
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter n=");
n = sc.nextInt();
if (n % 10 == 7 || n % 7 == 0)
{
System.out.println("Buzz number");
}
else
{
System.out.println("Not Buzz number");
}
}
}
Output:
Enter n=147
Buzz number
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.
import java.util.Scanner;
public class CoPrimeNumbers
{
public static void main(String[] args)
{
int a, b, gcd = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a=");
a = sc.nextInt();
System.out.print("Enter b=");
b = sc.nextInt();
int min, max;
min = a;
if (min > b)
{
min = b;
max = a;
}
else
{ min = a;
max = b;
}
while (max > min)
{ int r = max % min;
if (r == 0)
{
gcd = min;
break;
}
else
{ max = min;
min = r;
}
}
if (gcd == 1)
{
System.out.println("Co Prime Numbers");
}
else
{
System.out.println("Not Co Prime Numbers");
}
}
}
Output:
Enter a=13
Enter b=15
Co Prime Numbers
11 + 32 + 53 = 1 + 9 + 125 = 135
import java.util.Scanner;
if(n==sum)
{
System.out.println("Disarium Number");
}
else
{
System.out.println("Not Disarium Number");
}
}
}
Output:
Enter number=135
Disarium Number
Enter number=6
1
2
3
6
1
23
456
7 8 9 10
11 12 13 14 15
Enter a=15
Enter b=18
GCD=3
Enter a=15
Enter b=18
LCM:90
Enter number=9
Neon Number
Enter number=12321
Palindrome Number
Output:
Enter number=6
Perfect Number
Enter number=17
Number is prime.
Prime Number Up to N Terms Program in
Java
import java.util.Scanner;
}
}
Output:
Output:
Enter number=1234
Reverce of Number=4321
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.
import java.util.Scanner;
Enter number=123
Spy Number
Sum of Digits Program in Java
If a number enter 5462 then sum of theses digits 5+4+6+2 = 17.
import java.util.Scanner;
Enter number=1234
Sum of digit=10
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.
import java.util.Scanner;
Enter a=5
Enter b=7
Twin Prime
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.
import java.util.Scanner;
Output:
Enter number=137
Twisted Prime
Number Series Program in Java
import java.util.Scanner;
12
int i = 1;
int d = 5;
do
{
d = d * 2;
System.out.println(d);
i++;
}
while (i <= 5);
Output:
10
20
40
80
160
WIN
WIN
Sum of Series Program
Example – 1 + (1+2) + (1+2+3) + …… n
import java.util.*;
class seriesprogram {
}
}
Series Program
import java.util.Scanner;
public class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int n = sc.nextInt();
int s = 0, c; // s for terms of series, c for counter to
generate n terms
for (c = 1; c <= n; c++) {
s = s * 10 + c;
System.out.print(s + " ");
}
}
}