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

Javaquestionbankcls8

The document contains a series of programming tasks in Java, each requiring the implementation of specific functionalities such as checking if a number is positive or negative, calculating profit or loss, and determining if a number is a palindrome. Each task is accompanied by a code snippet that demonstrates how to achieve the desired outcome. The tasks cover a range of basic programming concepts including conditionals, loops, and arithmetic operations.

Uploaded by

A350fan boy
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)
7 views

Javaquestionbankcls8

The document contains a series of programming tasks in Java, each requiring the implementation of specific functionalities such as checking if a number is positive or negative, calculating profit or loss, and determining if a number is a palindrome. Each task is accompanied by a code snippet that demonstrates how to achieve the desired outcome. The tasks cover a range of basic programming concepts including conditionals, loops, and arithmetic operations.

Uploaded by

A350fan boy
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/ 5

Application based Questions:

1. Write a program to check if a number if positive or negative.

2. Write a program to check if a number if even or odd.

3. Write a program to check if a number is divisible by 7 or 3.

4. Write a program to check if the number id single digit, double digit number or

more.

5. Write a program to check a three-digit number is a palindrome or not.

6. Write a program to check if an entered year is a leap year or not.

7. Write a program to check if a number is neon number or not. A neon number is a

number that is either divisible by 9 or ends with 9.

public class p7
{
public static void setdata(int num)
{
int square=num*num;
int first_num= square/10;
int last_num=square%10;
int sum=first_num + last_num;
if(sum==num)
{

System.out.println("it is a neon number");


}
else
{

System.out.println("it is not a neon number");


}

}
}
8. Write a program to calculate the profit or loss based on the read cost price and

selling price.

public class p8
{
public static void setdata(int cost_price, int selling_price)
{
double profit, profit_percent,loss,loss_percent;
if(selling_price>cost_price)
{
profit=selling_price-cost_price;
profit_percent=(profit/cost_price)*100;
System.out.println("the profit is"+ profit);
System.out.println("the profit_percent is"+ profit_percent);
}
else
{
loss=cost_price-selling_price;
loss_percent=(loss/cost_price) *100;
System.out.println("the loss is"+loss);
System.out.println("the loss_percentage is"+loss_percent);
}

}
}
9. Write a program to calculate a 10% discount if the amount is above 10000 else a

discount of 7.5%. Display the discount received and the final billing amount to be

paid.

public class p9
{
public static void setdata(int amount)
{
double discount,total_amt;
if(amount>10000)
{
discount=.1*amount;
total_amt=amount-discount;
System.out.println("the discount is"+discount);
System.out.println("the total amount is"+total_amt);
}
else
{
discount=.075*amount;
total_amt=amount-discount;
System.out.println("the discount is"+discount);
System.out.println("the total amount is"+total_amt);
}

}
}
10. Write a program in java to read three numbers and display the largest of the three

Numbers.

public class p10


{
public static void setdata(int a,int b,int c)
{
if((a>b)&&(a>c))
{
System.out.println("a is the greatest number");
}
else if((b>c)&&(b>a))
{
System.out.println("b is the greatest number");
}
else
{
System.out.println(" c is the greatest number");
}

}
}
11. Write a program to read two numbers and display the smallest of the two.

public class p11


{
public static void setdata(int a,int b)
{
if(a<b)
{
System.out.println("a is the smallest number");
}
else
{
System.out.println("b is the smallest number");
}
}
}
12. Write a program to read a number and a character. If the character is ‘S’ display

the square of the number. If the character is ‘C’ then display the cube of the

number.

Ans:-

public class p12


{
public static void set(int x, char ch)
{
if(ch=='S')
{
int sq=x*x;
System.out.println("the square of the number is"+sq);
}
else if(ch=='C')
{
int cube=x*x*x;
System.out.println("the cube of the number is "+cube);
}
}
}
13. Write a program to read two numbers. If both numbers are even then display their

sum else display their product.

Ans:-

Ans:-

public class p13


{
public static void setdata(int num1, int num2)
{
if((num1%2==0)&&(num2%2==0))
{
int sum=num1+num2;
System.out.println(" the sum of two numbers is "+sum);
}
else
{
int p=num1*num2;
System.out.println("the product of two numbers is"+p);
}
}
}

14. Write a program to read a character and check if the character is a vowel or a

consonant.

Ans:-
public class p14
{
public static void set(char ch) {
if((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u')) {
System.out.println("It is a vowel"); }
else
{
System.out.println(" it is a consonant");
}}}
15. Write a program to read two numbers and a Boolean value. For Boolean true

display the area and perimeter of a rectangle assuming the two numbers are the

length and width. For a Boolean false calculate and display the surface area and

volume of a cylinder assuming the parameters as height and radius of the cylinder.

[Surface Area=2πrh+2πr2 , Volume=π r² h]

Ans:- public class p15

public static void main(int l, int b, double r,double h,boolean f)


{

if(f==true)

int area_rectangle= l*b;

int perimeter_rectangle=2*(l+b);

System.out.println("the area of the rectangle is "+area_rectangle);

System.out.println(" the perimeter of the rectangle is"+perimeter_rectangle);

else

double surface_area_cylinder= 2*3.14*(r*h+r*r);

double volume_cylinder= 3.14*r*r*h;

System.out.println("the surface area of a cylinder is "+surface_area_cylinder);

System.out.println(" the volume of the cylinder is"+volume_cylinder);

You might also like