P. R.
Khatiwala Vidya Sankul
Std 12 Sci/Comm./Arts Term-1 Practical Exam Marks:- 50
1- Palindrome Program in Java
Palindrome number in java: A palindrome number is a number that is same after
reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers.
It can also be a string like LOL, MADAM etc.
class PalindromeExample{
public static void main(String args[]){
int r,sum=0,temp;
int n=505; //It is the number variable to be checked for palindrome
temp=n;
while(n>0){ Output:
r=n%10; //getting remainder palindrome
sum=(sum*10)+r; number
n=n/10;
}
if(temp==sum)
[Link]("palindrome number ");
else
[Link]("not palindrome");
} }
2. Program To find Prime no.
public class PrimeExample{
public static void main(String args[]){
int i,m=0,flag=0;
int n=3; //it is the number to be checked
m=n/2;
if(n==0||n==1){
[Link](n+" is not prime number");
}else{
for(i=2;i<=m;i++){
if(n%i==0){
[Link](n+" is not prime number");
flag=1;
break;
} }
if(flag==0) { [Link](n+" is prime number"); }
} //end of else
} }
2- The code written below depicts how for loop is implemented in Java Language
Public class MyClass
{
public static void main(String[] args) {
{
for (int i = 0; i < 5; i++)
{
[Link](i);
}
}
}
Output:
0
1
2
3
4
3- // Java program to find circumference of circle
import [Link].*;
class Geometry {
// utility function
static double circumference(double r){
double PI = 3.1415;
double cir = 2*PI*r;
return cir;
}
// driver function
public static void main (String[] args) {
double r = 5;
double result = [Link](circumference(r) * 1000) / 1000.0;
[Link]("Circumference = "+ result);
}
}
Output :
Circumference = 31.415
/*
5. * Java program to find the area of a circle
*/
public class Circle
{
public static void main(String[] args)
{
int r;
double pi = 3.14, area;
Scanner s = new Scanner([Link]);
[Link]("Enter radius of circle: ");
r = [Link]();
area = pi * r * r;
[Link]("Area of circle: "+area);
}
}
Program 6- Arithmetic related Prog. From chap 7
Compilation
Prog. Run
Output
Program 7- CallCost Program from Chap 7
/ **
* This class implements a simple program that
* will compute the cost of phone call and update balance
*/
public class CallCost
{
public static void main (String [] args)
{
/*declare variables */
double balance; // balance amount in rupees
double rate; // call rate; rupees per second
double duration; // call duration in seconds
double cost; // cost of last call
/*computations. */
balance = 170;
rate = 1.02;
duration = 37;
cost = duration * rate; // compute the cost
balance = balance - cost; // update balance amount
/*display results */
[Link]("Call Duration: ");
[Link] (duration);
[Link]("Seconds");
[Link]("Balance:" + balance + "Rupees ");
} // end of main()
} // end of class CallCost
XXXXXXXXXXXXXXXXXXXXXX