0% found this document useful (0 votes)
11 views15 pages

IX Project 24 25 (Answer)

The document contains ten Java programs, each demonstrating different functionalities such as calculating charges based on kilometers traveled, computing volumes of geometric shapes, performing basic arithmetic operations, generating Fibonacci series, and identifying special numbers. Each program includes variable descriptions, sample outputs, and user prompts for input. The programs utilize various data types and control structures to achieve their objectives.

Uploaded by

vandit442
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)
11 views15 pages

IX Project 24 25 (Answer)

The document contains ten Java programs, each demonstrating different functionalities such as calculating charges based on kilometers traveled, computing volumes of geometric shapes, performing basic arithmetic operations, generating Fibonacci series, and identifying special numbers. Each program includes variable descriptions, sample outputs, and user prompts for input. The programs utilize various data types and control structures to achieve their objectives.

Uploaded by

vandit442
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/ 15

[Ninth Project]

Program 1

import java.util.*;
class pro1
{
public static void main()
{
Scanner sc1=new Scanner(System.in);
Scanner sc2=new Scanner(System.in);

String name;
long phno;
double charge;
int km;

System.out.println("Enter the name of the customer");


name=sc2.nextLine();

System.out.println("Enter the phone number");


phno=sc1.nextLong();

System.out.println("Enter the number of km");


km=sc1.nextInt();

if(km<=10)
{
charge=km*10;
}
else if(km>=11 && km<=20)
{
charge=10*10+(km-10)*8;
}
else if(km>=21 && km<=35)
{
charge=10*10+10*8+(km-20)*5;
}
else if(km>=36 && km<=55)
{
charge=10*10+10*8+15*5+(km-35)*4;
}
else
{
charge=10*10+10*8+15*5+20*4+(km-55)*2;
}

System.out.println("Name Phone No Kilometers Charge");


System.out.println("--------------------------------------------");
System.out.println(name+" \t "+phno+" \t "+km+" \t "+charge);
}
}
Output

Enter the name of the customer


Keshvi
Enter the phone number
6243778905
Enter the number of km
23
Name Phone No Kilometers Charge
--------------------------------------------
Keshvi 6243778905 23 195.0

Variable Description Table:

Variable Data Description


Type

name String To accept the name of the customer

phno long To accept the phone number of the customer

km int To store the number of kilometres

charge double To calculate and store the total amount to be paid

Program 2

import java.util.*;
class Volume
{
public static void main ()
{
Scanner sc1=new Scanner(System.in);
Scanner sc2=new Scanner(System.in);

double r,l,b,h,radius,vol,volume,v;

System.out.println("a for volume of cuboid ");


System.out.println("b for volume of cylinder ");
System.out.println("c for volume of sphere ");

System.out.println("Enter your choice");


char ch=sc2.next().charAt(0);
switch(ch)
{
case 'a':

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


l=sc1.nextDouble();

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


b=sc1.nextDouble();

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


h=sc1.nextDouble();

vol=l*b*h;

System.out.println("Volume of cuboid="+vol);
break;

case 'b':

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


r=sc1.nextDouble();

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


h=sc1.nextDouble();

volume=3.14*r*r*h;

System.out.println("Volume of Cylinder="+volume);
break;

case 'c':
System.out.println("Enter the radius of sphere");
radius=sc1.nextDouble();

v=4.0/3*3.14*radius*radius*radius;
System.out.println("Volume of Sphere="+v);
break;
default:
System.out.println("Invalid input");
}
}
}

Output

a for volume of cuboid


b for volume of cylinder
c for volume of sphere
Enter your choice
b
Enter the value of radius
2
Enter the value of height
3
Volume of Cylinder=37.68

Variable Description Table:


Variable Data Type Description
r double To accept the radius

radius double To accept the radius of


sphere
h double
To accept the height

l double To accept the length

volume double To store the volume


(Cylinder)

b double To accept the breadth

To store the
double volume(sphere)
v
To store the
vol double volume(cuboid)
Program 3

import java.util.*;
class Swi
{
public static void main ()
{
Scanner sc=new Scanner(System.in);

int a,b,add,sub,mul,div,m;

System.out.println("1. Addition ");


System.out.println("2. Subtraction ");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Modulus");

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


a=sc.nextInt();

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


b=sc.nextInt();

System.out.println("Enter your choice");


int choice=sc.nextInt();

switch(choice)
{
case 1:
add=a+b;
System.out.println("Addition="+add);
break;
case 2:
sub=a-b;
System.out.println("Subtraction="+sub);
break;
case 3:
mul=a*b;
System.out.println("Multiplication="+mul);
break;
case 4:
div=a/b;
System.out.println("Division="+div);
break;
case 5:
m=a%b;
System.out.println("Modulus="+m);
break;

default:
System.out.println("Invalid");
}
}
}
Output
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
Enter the value of a
5
Enter the value of b
6
Enter your choice
5

Modulus=5

Variable Description Table:


Variable Data Type Description
a Int To accept the value of a
b int To accept the value of b
add Int To store the addition result
sub Int To store the subtraction
result
mul Int To store the multiplication
result
div Int To store the division result
m Int To store the modulus
result
Program 4

import java.util.*;
class fibonacci
{
public static void main()
{
Scanner sc= new Scanner(System.in);

System.out.println("Enter the number of terms");


int n=sc.nextInt();

int a=0,b=1,i;

for(i=1;i<=n;i++)
{
if(i==1)
{
System.out.print(a+"\t");
}
else if(i==2)
{
System.out.print(b+"\t");
}
else
{
int c=a+b;
System.out.print(c+"\t");
a=b;
b=c;
}
}
}
}

Output
Enter the number of terms
10

0 1 1 2 3 5 8 13 21 34

Variable Description Table:


Variable Data Type Description
a Int To store the value of a
b int To store the value of b
i Int As a loop variable
c Int As a temp variable
n Int To store the number of
terms
Program 5

Import java.util.*;
class Loop
{
public static void main()
{
Scanner sc = new Scanner(System.in);

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


int n = sc.nextInt();

int i,sume=0,cnt=0;
for(i=n;i>=1;i--)
{
if(i%2==0)
{
sume=sume+i;
cnt++;
}
}

double avg=(double)sume/cnt;
System.out.println("Average is="+avg);
}
}

Output
Enter the value of n
20
Average is=11

Variable Description Table:


Variable Data Type Description
sume Int To store the sum of
numbers
cnt int To store the count of
numbers
i Int As a loop variable
avg Double To store the average
n Int To store the number of
terms
Program 6

import java.util.*;
class Ser
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of X");
int X=sc.nextInt();
System.out.println("Enter the number of n");
int n=sc.nextInt();
double cnt,sum=0,i=1;
for(cnt=1;cnt<=n;cnt++)
{
if(cnt%2==0)
{
sum=sum-Math.pow(X,i)/i;
}
else
{
sum=sum+Math.pow(X,i)/i;
}
i=i+2;
}
System.out.println("Sum of series="+sum);
}
}

Output

Enter the number of X


3
Enter the number of n
5
Sum of series=1917.1714285714286

Variable Description Table:

Variable Data type Despcription


X Int To accept the value of X

n Int To accept the value of n

cnt Double To count the number of


digits

sum Double To calculate and store the


sum

i Double Looping variable


Program 7

import java.util.*;
class Ser
{
public static void main()
{
Scanner sc=new Scanner(System.in);

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


int n=sc.nextInt();

double cnt,i=1,value;

for(cnt=1;cnt<=n;cnt++)
{
value=Math.pow(i,2)-1;
System.out.print((int)value+"\t");
i++;
}
}
}

Output

Enter the any number


5
0 3 8 15 24
Variable Description Table:

Variable Data type Despcription


n int To accept the value of n

cnt double To count the number of


digits

i double Looping variable

value double To store the value

Program 8

import java.util.*;
class Ser
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter any number");
int n=sc.nextInt();
double i,sum=0;

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

Output

Enter any number


5
Sum of series=3413.0
Variable Description Table:

Variable Data type Despcription


n Int To store the value of n

i double Looping variable

sum Double To calculate and store the


sum
Program 9

import java.util.*;
class Loop
{
public static void main()
{

Scanner sc = new Scanner(System.in);

System.out.println(“Enter the number”);


Int num = sc.nextInt();

int rem,sum=0,mul=1,total,temp=num;

if (num>=10 && num<=99)


{
while(num>0)
{
rem=num%10;
sum=sum+rem;
mul=mul*rem;
num=num/10;
}

total=sum+mul;

if(total==temp)
{
System.out.println("Special 2-digit number");
}
else
{
System.out.println("Not a special 2-digit number");
}
}
else
{
System.out.println("Invalid input number should have 2 digits
only");
}
}
}

Output
Enter the number
54

Not a special 2-digit number


Variable Description Table:
Variable Data Type Description
num Int To store the input
rem int To store the extracted digit
sum Int To store the sum of digits
mul int To store the product of
digits
total Int To store the sum+mul
value
temp Int As a temp variable

Program 10

import java.util.*;
class Spy
{
public static void main()
{
int rem,num,sum=0,cnt=0;

Scanner sc=new Scanner(System.in);

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


num=sc.nextInt();

while(num>0)
{
rem=num%10;
sum=sum+rem;
cnt++;
num=num/10;
}
if(sum==cnt)
{
System.out.println("SUPERSPY NUMBER");
}
else
{
System.out.println("NOT A SUPERSPY NUMBER");
}
}
}

Output
Enter any number
111

SUPERSPY NUMBER
Variable Description Table:
Variable Data Type Description
num Int To store the input
rem int To store the extracted digit
sum Int To store the sum of digits
cnt int To store the count of digits

You might also like