Académique Documents
Professionnel Documents
Culture Documents
import java.util.Scanner;
import java.lang.Math ;
public class co_prime
{
public static void main(String args[])
{
int n1,n2,flage=0,i,min;
Scanner in = new Scanner(System.in);
System.out.print("enter two numbers ");
n1 = in.nextInt();
n2 = in.nextInt();
min=Math.min(n1,n2);
if((n1-n2==2)||(n2-n1== 2))
{
for(i=2;i<=min;i++)
{
if( (n1%i==0) && (n2%i== 0))
{
flage = 1;
break;
}
}
}
if(flage == 1)
System.out.println("\n the numbers are not co prime numbers ");
else
System.out.println("\n the numbers are co prime numbers "):
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
6) Write a program to accept a no. & display the new number after removing all
zeros.
import java.util.Scanner;
public class remove_zero_from_number
{
public static void main(String args[])
{
int num ,rev_num=0,rem=0,i,n;
Scanner in = new Scanner(System.in);
System.out.println("\n Enter an Integer ");
num = in.nextInt();
System.out.println("You entered "+num);
n=num;
while(n>0)
{
rem= n%10;
if(rem != 0)
rev_num= rev_num*10+rem;
n=n/10;
}
System.out.println("The reverse of the number is after deleting zeros "+rev_num);
while(rev_num>0)
{
rem=rev_num%10;
n= n*10+rem;
rev_num=rev_num/10;
}
System.out.println("The number after deleting zeros is "+n);
}}
PRINT THE FOLLOWING PATTERN :
A
A a
A a a
A a a a
A a a a a
public class pyramid_pattern
{
public static void main(String args[])
{
int i,j,k,space=5;
for(i=1;i<=5;i++ )
{ for(j=1;j<=space-i;j++)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(" a");
System.out.println("");
}
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1 2 3 4 5 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DUCK NUMBER
A Duck number is a number which has 0 in its digits.
import java.util.*;
public class DuckNumber
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to be checked.");
int num=ob.nextInt();
boolean duck=false;
int temp=num;
while(temp!=0)
{
int lastdigit=temp%10;
if(lastdigit==0)
{
duck=true;
break;
}
temp=temp/10;
}
if(duck==true)
{
System.out.println(num+" is a Duck Number.");
}
else
{
System.out.println(num+" is not a Duck Number.");
}
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
import java.util.Scanner;
System.out.println(“Enter a number”);
for(int i=0;i<=9;i++)
while(n!=0)
d=n%10;
if(d==i)
f++;
n=n/10;
n=n1;
if(f==0)
continue;
f=0;
@@@@@@@@@@@@@@@@@@@@@@
Write a program to accept a number and check whether the number is present in the
Fibonacci series or not. The program displays the message accordingly.
import java.util.Scanner;
System.out.println(“Enter a number”);
while(c<n)
a=b;
b=c;
c=a+b;
if(c==n)
break;
if(c>n)
Sample Input: 58
import java.util.Scanner;
System.out.println(“Enter a number”);
for(int i=1;i<=n;i++)
if(n%i==0)
c++;
if(c!=2)
else
while(n!=0)
n1=n1*10+(n%10);
n=n/10;
c=0;
for(int j=1;j<=n1;j++)
if(n1%j==0)
c++;
if(c==2)
else
A number is said to be Unique if digits of a number are not repeated in it. Write a
program to accept a number and check whether the number is Unique or not. The
program displays the message accordingly.
System.out.println(“Enter a number”);
while(n!=0)
d=n%10;
f[d]++;
n=n/10;
for(i=0; i<=9;i++)
if(f[i]>1)
break;
if(i==9)
break;
if(f[i]>1)
else
.Write a program to accept two numbers and check whether they are twin prime or
not.
import java.util.Scanner;
else
if(a%i==0)
c++;
if(b%j==0)
d++;
else