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

Ten Computer Project

The document contains 10 Java programs that demonstrate various programming concepts like loops, conditionals, methods, classes, input/output etc. Program 1 checks if a number is happy or not. Program 2 calculates the sum of a series. Program 3 calculates another series sum. The remaining programs contain patterns, number conversions, tax calculations and digit square sums.

Uploaded by

Yash Jinwala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Ten Computer Project

The document contains 10 Java programs that demonstrate various programming concepts like loops, conditionals, methods, classes, input/output etc. Program 1 checks if a number is happy or not. Program 2 calculates the sum of a series. Program 3 calculates another series sum. The remaining programs contain patterns, number conversions, tax calculations and digit square sums.

Uploaded by

Yash Jinwala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

X-Project 2021-2022

Program 1

import java.io.*;
class Happy
{
public static void main (String args[])throws IOException
{
int rem,sum=0,num,sq;
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(reader);

System.out.println("Enter any number:");


String v1=in.readLine();
num=Integer.parseInt(v1);

while(num>9)
{
sum=0;
while(num>0)
{
rem=num%10;
sq=rem*rem;
sum=sum+sq;
num=num/10;
}
num=sum;
}
if(num==1)
{
System.out.println("Happy number ");
}
else
{
System.out.println("Not a happy number");
}
}
}

Output

Enter any number:


28
Happy number
Program 2

import java.io.*;
class Ser
{
public static void main (String args[])throws IOException
{
double x,n,i=1,j,sum=0,f,cnt;

InputStreamReader reader=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(reader);

System.out.println("Enter the value of x");


String v1=in.readLine();
x=Integer.parseInt(v1);

System.out.println("Enter the value of n");


String v2=in.readLine();
n=Integer.parseInt(v2);

for(cnt=1;cnt<=n;cnt++)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
sum=sum+f/x;
i=i+2;
}
System.out.println("Sum of series= "+sum);
}
}

Output

Enter the value of x


2
Enter the value of n
5

Sum of series= 184023.5


Program 3

import java.io.*;
class Ser
{
public static void main (String args[])throws IOException
{
double x,n,i=1,j,sum=1,f,cnt;

InputStreamReader reader=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(reader);

System.out.println("Enter the value of x");


String v1=in.readLine();
x=Integer.parseInt(v1);

System.out.println("Enter the value of n");


String v2=in.readLine();
n=Integer.parseInt(v2);

for(cnt=1;cnt<=n;cnt++)
{
f=1;
for(j=1;j<=i;j++)
{
f=f*j;
}
sum=sum+Math.pow(x,i)/f;
i=i+1;
}
System.out.println("Sum of series= "+sum);
}
}

Output

Enter the value of x


3
Enter the value of n
6
Sum of series= 19.412499999999998
Program 4

class Patz
{
public static void main(String args[])
{
char i,j,s,z=1;

for(i='e';i>='a';i--)
{
for(s=1;s<z;s++)
{
System.out.print(" ");
}

for(j='a';j<=i;j++)
{
System.out.print(j);
}
++z;
System.out.println();
}
}
}

Output

abcde
abcd
abc
ab
a

Program 5

class Patz
{
public static void main(String args[])
{
int i,j;

for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
}
}

Output

55555
4444
333
22
1
Program 6

class Patz
{
public static void main(String args[])
{
int i,j;

for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}

Output

1
12
123
1234
12345

Program 7

class Patz
{
public static void main(String args[])
{
char i,j,s,z=4;

for(i='A';i<='E';i++)
{
for(s=1;s<=z;s++)
{
System.out.print(" ");
}

for(j='A';j<=i;j++)
{
System.out.print(j);
}
--z;
System.out.println();
}
}
}

Output

A
AB
ABC
ABCD
ABCDE
Program 8
import java.io.*;
class Word
{
public static void main(String args[])throws IOException
{
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(reader);

System.out.println("Enter any number: ");


String v1=in.readLine();
int n=Integer.parseInt(v1);

int rem,rev=0;

while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
while(rev>0)
{
rem=rev%10;

if(rem==0)
{
System.out.print("zero ");
}
if(rem==1)
{
System.out.print("one ");
}
if(rem==2)
{
System.out.print("two ");
}
if(rem==3)
{
System.out.print("three ");
}
if(rem==4)
{
System.out.print("four ");
}
if(rem==5)
{
System.out.print("five ");
}
if(rem==6)
{
System.out.print("six ");
}
if(rem==7)
{
System.out.print("seven ");
}
if(rem==8)
{
System.out.print("eight ");
}
if(rem==9)
{
System.out.print("nine ");
}
rev=rev/10;
}
}
}

Output

Enter any number:


124
one two four

Program 9

import java.io.*;
class IncomeTax
{
public static void main(String args[])throws IOException
{
double tax;
int age,T1;

InputStreamReader ISR=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(ISR);

System.out.println("Enter the age");


String v1=in.readLine();
age=Integer.parseInt(v1);

System.out.println("Enter the Gender");


String gender=in.readLine();

System.out.println("Enter the Income");


String v2=in.readLine();
T1=Integer.parseInt(v2);

if(age>65 || gender=="Female")
{
System.out.println("Wrong Category");
}
if(age<=65 && gender=="Male")
{
if(T1<=160000)
{
System.out.println("Nil");
}
else if(T1>=160001 && T1<=500000)
{
tax=(T1-160000)*0.10;
System.out.println("Income tax is="+tax);
}
else if(T1>=500001 && T1<=800000)
{
tax=(T1-800000)*0.20+34000;
System.out.println("Income tax is="+tax);
}
else
{
tax=(T1-800000)*0.30+94000;
System.out.println("Income tax is="+tax);
}
}
}
}
Output

Enter the age


45
Enter the Gender
Male
Enter the Income
190000
Income tax is=3000.0

Program 10

import java.io.*;
class Pro
{
public static void main(String args[])throws IOException
{
int n,rem;
double sqrt,sum=0;

InputStreamReader reader =new InputStreamReader (System.in);


BufferedReader in =new BufferedReader(reader);

System.out.println("Enter any number:");


String v2=in.readLine();
n=Integer.parseInt(v2);

while(n>0)
{
rem=n%10;
sqrt=Math.pow(rem,2);
sum=sum+sqrt;
n=n/10;
}
System.out.println("Sum of squares of digit= "+sum);
}
}

Output

Enter any number:


159
Sum of squares of digit= 107.0

You might also like