How to design a overloaded function. java icse class 10

Make class Check to design the overloaded function primes() as:
i. void primes(long num) – To print only prime digits from the number stored in ‘num’.
ii. void primes(int n,int m) – To print whether ‘n’ and ‘m’ are Twin-Prime or not otherwise print a suitable message. Two numbers are said as Twin-Prime if both the numbers are prime and their difference is 2.

import java.util.*;
class Check
{
public static void primes (long num)
{
long x=num,d=0,y=0,i=0;
while(x>0)
{
d=x%10;
y=d;
for(int j = 2 ; j<y ; j++)
{
if(y%j==0)
i++;
}
if(i==0)
System.out.println(d);
x=x/10;
i=0;
}
}
public static void primes( int n ,int m)
{
int x=n,y=m,d=0,j=0;
for(int i = 2 ; i<x ; i++)
{
if(x%i==0)
d++;
}
for(int t = 2 ; t<y ; t++)
{
if(y%t==0)
j++;
}
if(d==0 && j==0)
{
if(n>m)
{
int l = n-m;
if(l==2)
System.out.println(“These are Twin Prime numbers”);
else
System.out.println(“These are not Twin Prime numbers”);
}
else
{
int l = m-n;
if(l==2)
System.out.println(“These are Twin Prime numbers”);
else
System.out.println(“These are not Twin Prime numbers”);
}
}
else
System.out.println(“These are not Twin Prime numbers”);
}
public static void main()
{

Scanner in = new Scanner(System.in);
System.out.print(“Enter a number = “);
long num = in.nextLong();
primes(num);
System.out.print(“Enter two numbers = “);
int n = in.nextInt(),m = in.nextInt();
primes(n,m);
}
}

In this post i have shared a java program which is mostly asked by students of computer science.

THANK YOU FOR VISITING OUR BLOG.For more related posts and anime,programing,gaming post please regularly check our blog.

Lavi Thakur

Recent Posts

How to make money as a Beginner Coder in 2025

Making money as a coder in 2025 is not much of a big or tough…

8 months ago

Lloyds Technology Centre : A Concise Guide

Lloyds Technology Centre, A tech and data company located in Hyderabad, India. They are  part of…

9 months ago

How to Increase Height at Any Age

How to Increase Height at Any Age Rise Above: How to Increase Height at Any…

10 months ago

The Hidden Beauty of Karrukha Wood: A Rare Masterpiece from Nature

In the fast-paced digital world, we often forget the timeless beauty that nature offers. Today,…

10 months ago

Top 10 Deadliest Kicks in Martial Arts [2024]

Top 10 Deadliest Kicks in Martial Arts: Master the Art of Knockouts Martial arts is…

11 months ago

How to Optimize Battery Life of Your Smartphone

How to Optimize Battery Life of Your Smartphone: Tips and Tricks for Prolonging Battery Health…

11 months ago