Computer Project - 10
Computer Project - 10
Computer Project - 10
Class – X
----------------------------------------------------------------------------------------------------------------------------------
1. WAP to input a number find its premorial.Primorial (denoted as Pn#) is a product
of first n prime numbers.
Input: n = 3
Output:30
Primorial = 2 * 3 * 5 = 30
As a side note, factorial is 2 * 3 * 4 * 5
Input: n = 5
Output: 2310
Primorial = 2 * 3 * 5 * 7 * 11
import java.util.Scanner;
class Perimorial
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Input a number,you want perimorial number");
int n=sc.nextInt();
int count=0;// to count number of prime number
int m=1,pro=1;// pro is use to store product of first n prime number
while(count<n)
{
int c=0;
for(int i=1;i<=m;i++)
{
if(m%i==0)
c++;
}
if(c==2)
{
pro=pro*m;
count++;
}
m++;
}
System.out.println("The perimorial number corrosponding to that number is:="+pro);
}
}
2. Write a program in java to input a number and arrange its digit in ascending order.
import java.util.Scanner;
class Accending
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Input a number:=");
int n=sc.nextInt();
for(int i=0;i<=9;i++)
{
int m=n;
while(m>0)
{
int d=m%10;
if(d==i)
System.out.print(d);
m=m/10;
}
}
}
}
3. Write a menu driven class to accept a number from the user and check whether it is
a Palindrome or a Perfect number.
(a) Palindrome number: (A number is a Palindrome which when read in reverse
order is same as in the right order)
Example: 11, 101, 151 etc.
(b) Perfect number: (A number is called Perfect if it is equal to the sum of its
factors other than the number itself.)
Example: 6 = 1 + 2 + 3
import java.util.Scanner;
class Pal_prime
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Input a number,you want to check");
int n=sc.nextInt();
int rev=0,flag1=0,flag2=0,t=n;
while(n>0)
{
int d=n%10;
rev=rev*10+d;
n=n/10;
}
if(t==rev)
{
flag1=1;// to check number is palindrom or not
}
int sum=0,temp=t;
for(int i=1;i<t;i++)
{
if(t%i==0)
sum=sum+i;// sum of factors
}
if(sum==t)
flag2=1;// to check number is perfect or not
int cu_root=(int)Math.cbrt(n);
int sum=0;// to store sum of digits
while(n>0)
{
int d=n%10;
sum=sum+d;
n=n/10;
}
if(sum==cu_root)
System.out.println("Number is Dudeney number");
else
System.out.println("Number is not a Dudeney number");
}
}
import java.util.Scanner;
class ISBN
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Input a number,you want to check");
long n=sc.nextLong();
long t=10,sum=0;
while(t>0)
{
long d=n%10;
sum=sum+d*t;
n=n/10;
t--;
}
if(sum%11==0)
System.out.println("Number is ISBN Number");
else
System.out.println("Number is not an ISBN Number");
}
}
7. Write a menu driven program to calculate and print the sum of the following series
using switch statement
(i) s = 1-3+5-7+------- n terms
(ii) (ii) s = / 1! − 3/ 3! + 5 /5! − − − − − −
import java.util.Scanner;
class Menu
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Which series sum you want");
System.out.println("1-3+5-7+------- n terms ");
System.out.println(" /1!− 3/3!+ 5/5!− − − − − − n terms");
System.out.println("Enter 1 for 1st series and 2 for second series");
int choice=sc.nextInt();
switch(choice)
{
case 1:
{
System.out.println("How many terms sum you want:=");
int n=sc.nextInt();
int sum=0;
for(int i=1;i<=n;i++)
{
if(i%2==1)
{
sum=sum+(2*i-1);
}else
{
sum=sum-(2*i-1);
}
}
System.out.println("Sum of the series is:="+sum);
break;
}
case 2:
{
System.out.println("How many terms sum you want:=");
int n=sc.nextInt();
System.out.println("Enter the value of x:=");
double x=sc.nextInt();
double sum=0;
for(int i=1;i<=n;i++)
{
int f=1;
for(int j=1;j<=(2*i-1);j++)
{
f=f*j;
}
if(i%2==1)
{
sum=sum+Math.pow(x,(2*i-1))/f;
}else
{
sum=sum-Math.pow(x,(2*i-1))/f;
}
}
System.out.println("Sum of the series is:="+sum);
break;
}
default:
System.out.println("Enter valid choice");
}
}
}
import java.util.Scanner;
class Count
{
int c;
Count()
{
c=0;
}
void increase()
{
c++;
}
void decrease()
{
c--;
}
void show()
{
System.out.println("The value of c after calling:="+c);
}
public static void main(String args[])
{
Count c1=new Count();
for(int i=1;i<=5;i++)
{
c1.increase();
}
c1.decrease();
c1.show();
}
}
import java.util.Scanner;
class Teacher
{
String name,add,sub;
long ph,sal;
double it;
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name:=");
name=sc.nextLine();
System.out.println("Enter address:=");
add=sc.nextLine();
System.out.println("Enter subject specification:=");
sub=sc.nextLine();
System.out.println("Enter phone number:=");
ph=sc.nextLong();
System.out.println("Enter monthly salary:=");
sal=sc.nextLong();
}
void compute()
{
long ysal=sal*12;// to store monthly salary
if(ysal>275000)
{
it=(ysal-275000)*10/100;
}
}
void display()
{
System.out.println("Teacher Name:="+name);
System.out.println("Address:="+add);
System.out.println("Phone Number:="+ph);
System.out.println("Subject Specification:="+sub);
System.out.println("Monthly salary:="+sal);
System.out.println("Income tax:="+it);
}
class Pattern1
{
public static void main(String args[])
{
int space=4;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=space;j++)
{
System.out.print(" ");
}
for(int k=1;k<=(2*i-1);k++)
{
System.out.print(i);
}
System.out.println();
space--;
}
}
}
Pattern B.
class Pattern2
{
public static void main(String args[])
{
int n=9,i,j,num=1;
int space=n-1;
for (j=1 ; j<=n ;j++)
{
num = j;
for ( i = 1 ; i <=space ; i++ )
System.out.print(" ");
space --;
for (i=1 ;i<=j;i++)
{
System.out.print(num%10);
num++;
}
num--;
num--;
for (i=1; i<j;i++)
{
System.out.print(num%10);
num--;
}
System.out.print("\n");
}
}
}
Pattern C.
class Pattern3
{
public static void main(String args[])
{
int space=4;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=space;j++)
{
System.out.print(" ");
}
for(int k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println();
space--;
}
int space1=2;
for(int i=3;i>=1;i--)
{
for(int j=1;j<=space1;j++)
{
System.out.print(" ");
}
for(int k=1;k<=(2*i-1);k++)
{
System.out.print("*");
}
System.out.println();
space1++;
}
}
}