KEMBAR78
Answer of Number Programs | PDF | Computer Programming | Software Engineering
0% found this document useful (0 votes)
49 views6 pages

Answer of Number Programs

Computer

Uploaded by

tunipradhan.027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

Answer of Number Programs

Computer

Uploaded by

tunipradhan.027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Smith Number

import java.util.*;
class SmithNumber
{
public static void main(String arr[])
{
Scanner sc = new Scanner(System.in);
int n,f=2,n1,t,s1=0,s2=0,d;

System.out.println("Enter a Number ");


n=sc.nextInt();
n1=n;
while(n1!=0)
{
d=n1%10;
s1=s1+d;
n1=n1/10;
}

while(n>1)
{
if(n%f==0)
{
t=f;
while(t!=0)
{
d=t%10;
s2=s2+d;
t/=10;
}
n=n/f;
}
else
f++;
}

if(s1==s2)
System.out.println("It is a Smith Number");
else
System.out.println("It is a not a Smith Number");
}
}
Evil Number

import java.util.Scanner;
public class EvilNum
{
public void display()
{
Scanner sc = new Scanner(System.in);
int n,n1,d,c=0;
String s="";
System.out.println("Enter a Number");
n=sc.nextInt();

n1=n;
while(n1!=0)
{
d=n1%2;
if(d == 1)
c++;
s=d+s;
n1=n1/2;
}

System.out.println("Binary Equivalent = "+s);

System.out.println("Number of 1's Present = "+c);

if(c%2 == 0)
System.out.println(n+" is an Evil Number");
else
System.out.println(n+" is not an Evil Number");
}
}
Fascinating Number

import java.util.Scanner;

public class FascinatingNum


{
public void display()
{
Scanner sc = new Scanner(System.in);
int n,n1,n2,n3,id1,id2,f = 0;
String st="";
char i;
System.out.print("Enter a Number ");
n = sc.nextInt();

if (n < 100)
{
System.out.println(n + " is not a Fascinating Number");
}
else
{
n1 = n * 2;
n2 = n * 3;
st = "" + n + n1 + n2;
for (i = '1'; i <= '9'; i++)
{
id1 = st.indexOf(i);
id2 = st.lastIndexOf(i);
if(id1 == -1 || id1 != id2)
{
f = 1;
break;
}
}
}

if (f == 0)
System.out.println(n + " is a Fascinating Number");
else
System.out.println(n + " is not a Fascinating Number");
}
}
Pyramid 1

public class Pyramid1


{
public void display()
{
int i, j = 0,k=0;

for (i = 1; i <= 5; i++, j = 0)


{
for (k = 1; k <= 5 - i; k++)
{
System.out.print(" ");
}

while (j != (2 * i - 1)) {
System.out.print("* ");
++j;
}

System.out.println();
}
}
}
Pyramid 2

public class Pyramid2


{
public void display()
{
int i,j=0,k=0;

for(i = 5; i >= 1; i--)


{
for(k = 1; k <= 5 - i; k++)
{
System.out.print(" ");
}

for(j=i; j <= 2 * i - 1; ++j)


{
System.out.print("* ");
}

for(j = 0; j < i - 1; ++j)


{
System.out.print("* ");
}

System.out.println();
}
}
}
Pyramid 3

public class Pyramid3


{

public void display()


{
int i,j=0,k = 0, c1 = 0, c2 = 0;

for (i = 1; i <= 5; i++)


{
for (k = 1; k <= 5 - i; k++)
{
System.out.print(" ");
c1++;
}

while (j!= 2 * i - 1)
{
if (c1 <= 5 - 1)
{
System.out.print((i + j) + " ");
c1++;
}
else
{
c2++;
System.out.print((i + j - 2 * c2) + " ");
}

j++;
}
c2 = c1 = j = 0;
System.out.println();
}
}
}

You might also like