0% found this document useful (0 votes)
50 views

Computer Project - 10

This file is great need of class 10 students in computer application..

Uploaded by

vaidhyanavneet05
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)
50 views

Computer Project - 10

This file is great need of class 10 students in computer application..

Uploaded by

vaidhyanavneet05
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/ 14

Computer Applications

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

if(flag1==1 && flag2==0)


System.out.println("Palindrom Number");
else if(flag1==0 && flag2==1)
System.out.println("Perfect Number");
else
System.out.println("Neither Palindrom Number or Perfect Number ");
}
}
4. A Dudeney number is a positive integer that is a perfect cube such that the sum of its
digits is equal to the cube root of the number. Write a program to input a number
and check and print whether it is a Dudeney number or not.
Example:
Consider the number 512.
Sum of digits = 5 + 1 + 2 = 8 Cube root of 512 = 8
As Sum of digits = Cube root of Number hence 512 is a Dudeney number.
import java.util.Scanner;
class Dudeney
{
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 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");
}
}

5. A number is known as ISBN (International standard book number) is a 10 digits


number, where the sum of all its digits multiply by its respective positions is divisible
by 11.
Example: 8711075597
(8X1+7X2+1X3+1X4+0X5+7X6+5X7+5X8+9X9+7X10)
=8+14+3+4+0+42+35+40+81+70
= 297
= 297%11
=0

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");
}
}

6. Design a class to overload a function polygon () as follows:


(i) void polygon (int n, char ch) :with one integer argument and one
character type argument that draws a filled square of side n using the
character stored in ch.
(ii) void polygon (int x, int y): with two integer arguments that draws a filled
rectangle of length x and breadth y, using the symbol ‘@’
(iii) void polygon (): with no argument that draws a filled triangle shown
below. Example:
(i) Input value of n=2, ch=’O’
Output: OO
OO
(ii) Input value of x=2, y=5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
***
import java.util.Scanner;
class Draw
{
void polygon(int n,char ch)// to print square
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(ch);
}
System.out.println();
}
}

void polygon(int x,int y)//// to print Rectangle


{
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
System.out.print("@");
}
System.out.println();
}
}

void polygon()//// to print Triangle


{
for(int i=1;i<=3;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the side of square:=");
int s1=sc.nextInt();
System.out.println("Enter the Character you want to print:=");
char ch=sc.next().charAt(0);

Draw d1=new Draw();


d1.polygon(s1,ch);// square calling
System.out.println("Enter the length of Rectangle:=");
int l=sc.nextInt();
System.out.println("Enter the breadth of Rectangle:=");
int b=sc.nextInt();
d1.polygon(l,b);// rectangle calling
d1.polygon();// triangle calling
}
}

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");
}
}
}

8. Define a class count in java as described below:


class name : count
Data members/ Instance variables:
c : int type variable
Member functions:
count() : default constructor
void increase() : to increase the value of c by 1
void decrease() : to decrease the value of c by 1
void show() : to display the value of c
Write a main() to create an object to the class and call the methods, 5 times
increase().

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();
}
}

9. Define a class Teacher whose specifications are given below:


data members/Instance variables:
name : to store the name
add : to store the address
ph : to store the phone number
sub : to store the subject specification
sal : to store the monthly salary of teacher
It : to store the income tax
Member functions:
(i) To input the details of the teacher, I.e. name, add, ph, sub and sal
(ii) To compute the income tax. It is 10% of above annual salary 2,75,000/-
(iii) To display all the details of the teacher
(iv) Write main() to create an object and call the above functions to enable the
task.

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);
}

public static void main(String args[])


{
Teacher t1=new Teacher();
t1.input();
t1.compute();
t1.display();
}
}
10.
Pattern A.

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++;
}
}
}

You might also like