0% found this document useful (0 votes)
28 views12 pages

9th STD Worksheet - 3 2024

The document contains a series of Java programming exercises that involve various tasks such as checking for BUZZ numbers, identifying vowels, determining digit counts, and calculating discounts based on input values. Each exercise includes a brief description and a sample code implementation. The programs utilize basic Java constructs like conditionals, loops, and input/output operations.

Uploaded by

saiadharrshn
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)
28 views12 pages

9th STD Worksheet - 3 2024

The document contains a series of Java programming exercises that involve various tasks such as checking for BUZZ numbers, identifying vowels, determining digit counts, and calculating discounts based on input values. Each exercise includes a brief description and a sample code implementation. The programs utilize basic Java constructs like conditionals, loops, and input/output operations.

Uploaded by

saiadharrshn
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/ 12

Worksheet 3

21) Write a Java program to input a number and check whether the number is BUZZ number or not. A
number is called as BUZZ number,if it is divisibleby 7 or ends with 7
import java.util.*;
class w3_1
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println ("Enter a number :");
int a=sc.nextInt(); /**stores integer value*/
if (a%7==0 || a%10==7)
System.out.println (a+ " is BUZZ number");
else
System.out.println (a+ " is not a BUZZ number");
}
}

22) Write a Java program to input a character and check whether it is a vowel character or not.
class w3_2
{
void main(char a) /**stores character value*/
{
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
System.out.println (a+ " is a vowel character");
else
System.out.println (a+ " is not a vowel character");
}
}

23) Write a Java program to input a number and check whether it is a single digit or double digit or triple digit
number.
import java.util.*;
class w3_3
{
void main()
{
Scanner sc=new Scanner (System.in);
System.out.println ("Enter a number:");
int a=sc.nextInt(); /**stores integer value*/
if (a>=0 && a<10)
System.out.println (a+ " is single digit number");
else if (a>=10 && a<100)
System.out.println (a+ " is a double digit number");
else if (a>=100 && a<1000)
System.out.println (a+ " is a triple digit number");
}
}
24) Write a Java program to input a character and check whether it is an uppercase or lowercase ordigit or Symbol
character.
class w3_4
{
void main(char a) /**stores character value*/
{
if (a>='a'&& a<='z')
System.out.println (a+ " is a lowercase character");
else if(a>='A'&& a<='Z')
System.out.println (a+ " is a uppercase character");
else if(a>='0'&& a<='9')
System.out.println (a+ " is a digit");
else
System.out.println (a+ " is a Symbol ");
}
}

25) Write a Java program to input a number in the range 1-10 and display the corresponding Roman numeral.
import java.util.*;
class w3_5
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println ("Enter a number:(Range 1 to 10)");
int a=sc.nextInt(); /**stores integer value*/
if (a==1)
System.out.println (a+ " = I");
else if(a==2)
System.out.println (a+ " = II");
else if(a==3)
System.out.println (a+ " = III");
else if(a==4)
System.out.println (a+ " = IV");
else if(a==5)
System.out.println (a+ " = V");
else if(a==6)
System.out.println (a+ " = VI");
else if(a==7)
System.out.println (a+ " = VII");
else if(a==8)
System.out.println (a+ " = VIII");
else if(a==9)
System.out.println (a+ " = IX");
else if(a==10)
System.out.println (a+ " = X");
else
System.out.println (" Not a valid input");
}
}
26) Write a Java Program to input a number and check whether it is a negative odd number or negative even number.
import java.util.*;
class w3_6
{
void display()
{
Scanner sc=new Scanner(System.in);
System.out.println ("Enter a number:");
int x=sc.nextInt(); /** stores an integer number*/
if ( x<0 && x%2==0)
System.out.println(x+ " is negative even number");
else if ( x<0 && x%2!=0)
System.out.println(x+ " is negative odd number");
}
}
27) Write a Java Program to input three numbers and find the smallest number.

import java.util.*;
class w3_7
{
void display()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter three numbers:");
int x=sc.nextInt(); /** stores an integer number*/
int y=sc.nextInt(); /** stores an integer number*/
int z=sc.nextInt(); /** stores an integer number*/
if ( x<y && x<z)
System.out.println(x+ " is smallest number");
else if ( y<x && y<z)
System.out.println(y+ " is smallest number");
else
System.out.println(z+ " is smallest number");
}
}
28. Write a Java Program to input selling price and cost price of an article and find whether the user has made profit
or loss. If made profit, display profit % otherwise display the loss % .

import java.util.*;
class w3_8
{
void display()
{
Scanner sc=new Scanner (System.in);
System.out.println ("Enter Cost Price :");
doublecp=sc.nextDouble(); /**stores cost price*/
System.out.println ("Enter Selling Price :");
doublesp=sc.nextDouble(); /**stores selling price*/
double LP,PP;

if(cp>sp)
{
LP = ((cp-sp)/cp)*100; /** Stores loss percent*/
System.out.println (LP+" Loss percent");
}
else
{
PP = ((sp-cp)/cp)*100; /** Stores Profit percent*/
System.out.println (PP+" Profit percent");
}
}
}
29 )Write a Java Program to input a number and check whether it is positive odd or positive even or negative odd or
negative even or zero.

import java.util.*;
class w3_9
{
void display()
{
Scanner sc=new Scanner (System.in);
System.out.println ("Enter a number:");
int x=sc.nextInt(); /**stores an integer number*/
if(x>0 && x%2==0)
System.out.println(x+ " is positive even number");
else if(x>0 && x%2==1)
System.out.println(x+ " is positive odd number");
else if(x<0 && x%2==0)
System.out.println(x+ " is negative even number");
else if(x<0 && x%2!=0)
System.out.println(x+ " is negative odd number");
else
System.out.println(x+" = Number is Zero");
}
}
30) Write a Java Program to find the temperature in Fahrenheit by using input statement when temperature is
accepted in Celsius. If the temperature is 98.6 degree F or more then display “Fever" otherwise "Normal".

import java.util.*;
class w3_10
{
void display()
{
Scanner sc=new Scanner (System.in);
System.out.println ("Enter a value for celcius:");
double c=sc.nextDouble(); /**stores Celsius*/
double f=(c*9/5.0) +32; /**stores Fahrenheit*/
if(f>=98.6)
System.out.println (f+" = Fever");
else
System.out.println (f+" = Normal"); }}
31) A cloth showroom has announced the following festival discounts on the purchase of items, based on the total
cost of the items purchased.
TOTAL COST DISCOUNT (in Percentage)
Up to 2000 5%
2001 TO 5000 25%
5001 TO 10000 35%
Above 10000 50%

Write a java program to input total cost and to compute and displaythe amount to be paid by the customer after
availing the discount
import java.util.*;
class w3_11
{
void main()
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter cost price :");
intcp = sc.nextInt(); /**stores cost price*/
if (cp>0 &&cp<=2000)
{
System.out.println ("Avail 5% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*5/100.0))); }
else if (cp>=2001 &&cp<=5000) {
System.out.println (" Avail 25% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*25/100.0))); }
else if (cp>=5001 &&cp<=10000) {
System.out.println ("Avail 35% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*35/100.0))); }
else if (cp> 10000) {
System.out.println ("Avail 50% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*50/100.0))); }
else
System.out.println ("Invalid input");
}
}
31) A cloth showroom has announced the following festival discounts on the purchase of items, based on the total
cost of the items purchased.
TOTAL COST DISCOUNT (in Percentage)
Upto 2000 5%
2001 TO 5000 25%
5001 TO 10000 35%
Above 10000 50%

Write a java program to input total cost and to compute and display the amount to be paid by the customer after
availing the discount

import java.util.*;
class w3_11
{
void main()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter cost price :");
int cp = sc.nextInt();/**stores cost price*/
if (cp>0 &&cp<=2000)
{
System.out.println("Avail 5% discount");
System.out.println(" Amount paid after discount="+(cp-(cp*5/100.0)));
}
else if (cp>=2001 &&cp<=5000)
{
System.out.println (" Avail 25% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*25/100.0)));
}
else if (cp>=5001 &&cp<=10000)
{
System.out.println ("Avail 35% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*35/100.0)));
}
else if (cp> 10000)
{
System.out.println ("Avail 50% discount");
System.out.println (" Amount paid after discount="+(cp-(cp*50/100.0)));
}
else
System.out.println ("Invalid input");
}
}
32) In an Examination, the grades are given according to the marks obtained. Write a program in Java to input the
student name and marks and display the grades accordingly:

MARKS GRADES
80 and above Distinction
60 or more but less than 80 First division
45 or more but less than 60 Second Division
40 or more but less than 45 Pass
Less than 40 Promotion not Granted

import java.util.*;
class w3_12
{
void main()
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter Name of the student :");
String name= sc.nextLine (); /**stores name of the student*/
System.out.println("Enter the marks :");
int marks = sc.nextInt(); /**stores marks obtained*/
if (marks>=80)
System.out.println ("DISTINCTION");
else if (marks>=60 && marks<80)
System.out.println ("FIRST DIVISION");
else if (marks>=45 && marks<60)
System.out.println ("SECOND DIVISION");
else if (marks>=40 && marks<45)
System.out.println ("PASS");
else
System.out.println ("PROMOTION NOT GRANTED");
}
}
33) Write a Java Program to input customer name and no. of units consumed and calculate and display the bill
amount along with the customer name based on the following criteria:

UNITS CONSUMED RATE/Unit in RS


First 30 units 3.00 per unit
Next 30 units 5.00 per unit
Next 40 units 7.00 per unit
Above 100 units 9.00 per unit

import java.util.*;
class w3_13
{
void main()
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter Customer Name:");
String name= sc.nextLine (); /**stores customer name*/
System.out.println ("Enter no. of units consumed :");
int units = sc.nextInt(); /**stores unit consumed*/
if (units<=30)
System.out.println ("Rate of "+units+"= "+(units*3.0));
else if (units>30 && units<=60)
System.out.println ("Rate of "+units+"= "+((30*3.0)+(units-30)*5.0));
else if (units>60 && units<=100)
System.out.println ("Rate of "+units+"= "+((30*3.0)+(30*5.0)+(units-60)*7.0));
else if (units>100)
System.out.println ("Rate of "+units+"= "+((30*3.0)+(30*5.0)+(40*7.0)+(units-100)*9.0));
}
}

34) Write a Java Program to input the distance travelled and compute and display the bus fare based on the following
DISTANCE IN KM FARE/km
First 1 Km Rs. 4.00
Next 4 km Rs. 6.00
Next 10 km Rs. 8.00
Next 15 km Rs. 10.00
import java.util.*;
class w3_14 {
void main() {
Scanner sc = new Scanner (System.in);
System.out.println ("Enter distance travelled:");
int d = sc.nextInt();/**stores distance travelled*/
if (d>0 && d<=1)
System.out.println ("Bus fare = 4");
else if (d>1 && d<=5)
System.out.println ("Bus fare = "+(4+(d-1)*6.0));
else if (d>5 && d<=15)
System.out.println ("Bus fare = "+(4+(4*6.0)+(d-5)*8.0));
else if (d>15)
System.out.println ("Bus fare = "+(4+(4*6.0)+10*8.0+(d-15)*10));
} }
35. Write a Java Program to input the age and distance travelled and compute the railway fare depending on the
criteria as given:
AGE (in years) DISTANCE (in km) FARE (in Rupees)
Below 10 Below 10 Rs.5
Between 10 and50 Rs.20
Above 50 Rs.50
Between 10 and 60 Below 10 Rs.10
Between 10 and 50 Rs.40
Above 50 Rs.80
Above 60 Below 10 Rs.10
Between 10 and 50 Rs.40
Above 50 Rs.80
import java.util.*;
class w3_15
{
Void calc()
{
Scanner sc=new Scanner (System. in);
System.out.println ("Enter the age");
int age=sc.nextInt(); /**stores age */

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


int d=sc.nextInt(); /**stores distance */
int fare=0; /**stores bus fare */
if(age>0 && age<10)
{
if(d>0 && d<10)
fare=5;
else if(d>=10 && d<=50)
fare=20;
else if(d>50)
fare=50;
else
System.out.println ("Wrong input");
}
else if(age>=10 && age <=60)
{
if(d>0 && d<10)
fare=10;
else if(d>=10 & d<=50)
fare=40;
else if(d>50)
fare=80;
else
System.out.println ("Wrong input");
}
else if(age>60)
{
if(d>0 && d<10)
fare=4;
else if(d>=10 & d<=50)
fare=15;
else if(d>50)
fare=35;
else
System.out.println ("Wrong input");
}
else
System.out.println ("Wrong input");
System.out.println ("Age is "+age);
System.out.println ("Distance is "+d);
System.out.println ("fare is "+fare);
}
}

36) Write a Java Program to input a symbol as ‘$’, or ‘&’, or ‘#’ or ‘@’ or ‘?’ and display its corresponding name using
switch statement .
class w3_16
{
void symbols(char c) //stores a character value
{
switch(c){
case '$':
System.out.println ("The symbol is= Dollar");break;
case '&':
System.out.println ("The symbol is= Ampersand");break;
case '#':
System.out.println ("The symbol is= Hash Tag");break;
case '@':
System.out.println("The symbol is= At the rate");break;
case '?':
System.out.println("The symbol is= Question mark");break;
default:
System.out.println("The symbol is= Wrong Input");
}
}
}
_____________________________________________________________________________________________
37) Write a Java Program to input a month number and display the correspomding season of the year w
import java.util.*;
class w3_17
{
void display()
{
Scanner sc=new Scanner (System.in);
System.out.println ("Enter the month");
int month=sc.nextInt();
switch (month){
case 3:
case 4:
case 5:
System.out.println("Spring"); break;
case 6:
case 7:
case 8:
System.out.println("Summer"); break;
case 9:
case 10:
case 11:
System.out.println("Autumn"); break;
case 12:
case 1:
case 2:
System.out.println("Spring"); break;
default:
System.out.println("Wrong Input");
}
}
}
38)A company announces revised Dearness Allowance (DA) and Special Allowance (SA) for their
employees as per the tariff given below:

Basic Salary Dearness Allowance (DA) Special Allowance (SA)


Upto Rs. 10,000 10% of Basic Salary 5% of Basic Salary
Rs. 10,001 to Rs. 20,000 12% of Basic Salary 8% of Basic Salary
Rs. 20,001 to Rs. 30,000 15% of Basic Salary 10% of Basic Salary
Rs. 30,001 and above 20% of Basic Salary 12% of Basic Salary
Write a Java Program to input Employee name and Basic Salary. Calculate the gross salary as, Gross
Salary=Basic Salary + Dearness Allowance + Special Allowance
Display the information in the given format:
Name Basic Dearness Allowance Special Allowance Gross Salary
xxx xxx xxx xxx xxx

import java.util.*;
class w3_18
{
void calculation()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the basic salary");
int basic=sc.nextInt();
doublesalary,da,hra;
if(basic>0 && basic<=10000){
da=basic*0.1;
hra=basic*0.05; }
else if(basic>10000 && basic<=20000){
da=basic*12.0/100;;
hra=basic*0.08; }
else if(basic>20000 && basic<=30000){
da=basic*15.0/100;;
hra=basic*0.1; }
else if(basic>30000) {
da=basic*0.2;
hra=basic*0.12; }
salary=basic+da+hra;
System.out.println();
}
}

You might also like