--------------------------------------------
1) //This program
displays Hello Friends.
class
HelloFriends{
public static
void main (String args[]){
System.out.println("Hello
Friends");
}
}
--------------------------------------------
2) Conversion
--------------------------------------------
class Conversion
{
public static
void main(String args[])
{
byte b;
int i = 500;
float f = 123.942f;
System.out.println("\nConversion of
float to byte.");
b = (byte) f;
System.out.println("float was " +
f + " and byte is " + b);
System.out.println("\nConversion of int to float.");
f = i;
System.out.println("integer was "
+ i + " and float is " + f);
}
}
--------------------------------------------
3)Square
--------------------------------------------
import java.io.*;
class Square {
public static
void main(String args[]) throws IOException{
int i,res;
BufferedReader br = new BufferedReader (new
InputStreamReader (System.in));
String str;
System.out.println("\nEnter a
number:");
str=br.readLine();
i=Integer.parseInt(str);
res=i*i;
System.out.println("The Square=" +
res);
}
}
--------------------------------------------
4) Product
--------------------------------------------
import java.io.*;
class Product{
public static
void main(String args[]) throws IOException{
int a,b,res;
BufferedReader br = new BufferedReader (new
InputStreamReader (System.in));
String str;
System.out.println("Enter two
numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
res=a*b;
System.out.println("The Product="
+ res);
}
}
import java.io.*;
class Product
{
public static void main(String args[]) throws IOException{
int m,n,p,i,j,k;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter values of m, n and p:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
p=Integer.parseInt(str);
int a[][]=new int [m][n];
int b[][]=new int [n][p];
int c[][]=new int [m][p];
System.out.println("Matrix A");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
System.out.println("Matrix B");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=p-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
b[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=p-1;j++)
{
c[i][j]=0;
for(k=0;k<=n-1;k++)
{
c[i][j]+=a[i][k]+b[k][j];
}
}
}
System.out.println("Product Matrix");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=p-1;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}
import java.io.*;
class Product
{
public static void main(String args[]) throws IOException{
int m,n,p,i,j,k;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter values of m, n and p:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
p=Integer.parseInt(str);
int a[][]=new int [m][n];
int b[][]=new int [n][p];
int c[][]=new int [m][p];
System.out.println("Matrix A");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
System.out.println("Matrix B");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=p-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
b[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=p-1;j++)
{
c[i][j]=0;
for(k=0;k<=n-1;k++)
{
c[i][j]+=a[i][k]+b[k][j];
}
}
}
System.out.println("Product Matrix");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=p-1;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}
--------------------------------------------
5) SimpleInterest
--------------------------------------------
import java.io.*;
class
SimpleInterest{
public static
void main(String args[]) throws IOException{
float p,n,r,si;
BufferedReader br = new BufferedReader (new
InputStreamReader (System.in));
String str;
System.out.println("Enter Principal
amount, no. of years and rate of interest:");
str=br.readLine();
p=Float.parseFloat(str);
str=br.readLine();
n=Float.parseFloat(str);
str=br.readLine();
r=Float.parseFloat(str);
si=p*n*r/100;
System.out.println("The Simple
Interest=" + si);
}
}
--------------------------------------------
6) Rectangle
--------------------------------------------
import java.io.*;
class Rectangle
{
public static
void main(String args[]) throws IOException{
float l,b,area,perimeter;
BufferedReader br = new BufferedReader (new
InputStreamReader (System.in));
String str;
System.out.println("Enter length and
breadth of rectangle:");
str=br.readLine();
l=Float.parseFloat(str);
str=br.readLine();
b=Float.parseFloat(str);
area=l*b;
perimeter=2*(l+b);
System.out.println("The Area=" +
area + "\nThe Perimeter=" + perimeter);
}
}
--------------------------------------------
7) Larger
--------------------------------------------
import java.io.*;
class Larger
{
public static void main(String args[]) throws IOException{
int a,b,large;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
large=(a>b)?a:b;
System.out.println("The Larger no.=" + large);
}
}
--------------------------------------------
8) Circle
--------------------------------------------
import java.io.*;
class Circle
{
public static void main(String args[]) throws IOException{
float r,area;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter radius:");
str=br.readLine();
r=Float.parseFloat(str);
area=3.14f*r*r;
System.out.println("The Area=" + area);
}
}
import java.io.*;
class Circle
{
private float r,area;
Circle(float x)
{
r=x;
}
void calculate()
{
area=3.14f*r*r;
}
void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main(String args[]) throws IOException{
float x;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Radius:");
str=br.readLine();
x=Float.parseFloat(str);
Circle c=new Circle(x);
c.calculate();
c.display();
}
}
import java.io.*;
class Circle
{
private float r,area;
Circle() throws IOException
{
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Radius:");
str=br.readLine();
r=Float.parseFloat(str);
}
void calculate()
{
area=3.14f*r*r;
}
void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main(String args[]) throws IOException{
Circle c=new Circle();
c.calculate();
c.display();
}
}
import java.io.*;
class Circle
{
private float r,area;
Circle(float x)
{
r=x;
}
void calculate()
{
area=3.14f*r*r;
}
void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main(String args[]) throws IOException{
float x;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Radius:");
str=br.readLine();
x=Float.parseFloat(str);
Circle c=new Circle(x);
c.calculate();
c.display();
}
}
import java.io.*;
class Circle
{
private float r,area;
Circle() throws IOException
{
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Radius:");
str=br.readLine();
r=Float.parseFloat(str);
}
void calculate()
{
area=3.14f*r*r;
}
void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main(String args[]) throws IOException{
Circle c=new Circle();
c.calculate();
c.display();
}
}
--------------------------------------------
9) Swap
--------------------------------------------
import java.io.*;
class Swap
{
public static void main(String args[]) throws IOException{
int a,b,temp;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
System.out.println("a=" + a + "\nb=" + b);
temp=a;
a=b;
b=temp;
System.out.println("After Swapping:\na=" + a + "\nb=" + b);
}
}
--------------------------------------------
10) Shift
--------------------------------------------
import java.io.*;
class Shift
{
public static void main(String args[]) throws IOException{
int a,res;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter a number:");
str=br.readLine();
a=Integer.parseInt(str);
res=a<<3;
System.out.println("After Shifting:\na=" + a + "\nResult=" + res);
}
}
--------------------------------------------
11) BitwiseOperations
--------------------------------------------
import java.io.*;
class BitwiseOperations
{
public static void main(String args[]) throws IOException{
int a,b;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter 2 numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
System.out.println("After ANDing:" + (a&b) + "\nAfter ORing:" + (a|b) + "\nAfter EXORing:" +(a^b) + "\nNOT of a:" + (~a) + "\nNOT of b:" + (~b));
}
}
--------------------------------------------
12) TwoDigit
--------------------------------------------
import java.io.*;
class TwoDigit
{
public static void main(String args[]) throws IOException{
int no,d1,d2;
no=Integer.parseInt(args[0]);
d2=no%10;
d1=no/10;
System.out.println("Digit 1:" + d1 + "\nDigit 2:" + d2);
}
}
import java.io.*;
class Digit
{
public static void main(String args[]) throws IOException{
int n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a single digit no:");
str=br.readLine();
n=Integer.parseInt(str);
switch(n)
{
case 0:System.out.println("Zero");
break;
case 1:System.out.println("One");
break;
case 2:System.out.println("Two");
break;
case 3:System.out.println("Three");
break;
case 4:System.out.println("Four");
break;
case 5:System.out.println("Five");
break;
case 6:System.out.println("Six");
break;
case 7:System.out.println("Seven");
break;
case 8:System.out.println("Eight");
break;
case 9:System.out.println("Nine");
break;
}
}
}
import java.io.*;
class Digit
{
public static void main(String args[]) throws IOException{
int n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a single digit no:");
str=br.readLine();
n=Integer.parseInt(str);
switch(n)
{
case 0:System.out.println("Zero");
break;
case 1:System.out.println("One");
break;
case 2:System.out.println("Two");
break;
case 3:System.out.println("Three");
break;
case 4:System.out.println("Four");
break;
case 5:System.out.println("Five");
break;
case 6:System.out.println("Six");
break;
case 7:System.out.println("Seven");
break;
case 8:System.out.println("Eight");
break;
case 9:System.out.println("Nine");
break;
}
}
}
import java.io.*;
class Digit
{
public static void main(String args[]) throws IOException{
int n,digit,rev=0;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a no:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
while(rev!=0)
{
digit=rev%10;
switch(digit)
{
case 0:System.out.print(" Zero");
break;
case 1:System.out.print(" One");
break;
case 2:System.out.print(" Two");
break;
case 3:System.out.print(" Three");
break;
case 4:System.out.print(" Four");
break;
case 5:System.out.print(" Five");
break;
case 6:System.out.print(" Six");
break;
case 7:System.out.print(" Seven");
break;
case 8:System.out.print(" Eight");
break;
case 9:System.out.print(" Nine");
break;
}
rev/=10;
}
}
}
--------------------------------------------
13) Largest
--------------------------------------------
import java.io.*;
class Largest
{
public static void main(String args[]) throws IOException{
int no1,no2,no3,large;
no1=Integer.parseInt(args[0]);
no2=Integer.parseInt(args[1]);
no3=Integer.parseInt(args[2]);
large=(no1>no2)?no1:no2;
large=(large>no3)?large:no3;
System.out.println("Largest no:" + large);
}
}
--------------------------------------------
14) Convert
--------------------------------------------
import java.io.*;
class Convert
{
public static void main(String args[]) throws IOException{
int a;
float b;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter a float number:");
str=br.readLine();
b=Float.parseFloat(str);
a=(int)b;
System.out.println("Integer part is:" + a);
}
}
--------------------------------------------
import java.io.*;
class Convert
{
public static void main(String args[]) throws IOException{
char a;
int b;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter an integer number:");
str=br.readLine();
b=Integer.parseInt(str);
a=(char)b;
System.out.println("ASCII equivalent is:" + a);
}
}
--------------------------------------------
15) Quadratic
--------------------------------------------
import java.io.*;
class Quadratic
{
public static void main(String args[]) throws IOException{
float a,b,c;
double x1,x2;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter the values of a, b and c:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
str=br.readLine();
c=Integer.parseInt(str);
x1=(-b+Math.pow((b*b-4*a*c),0.5))/(2*a);
x2=(-b-Math.pow((b*b-4*a*c),0.5))/(2*a);
System.out.println("The roots are:" + x1 + " and " + x2);
}
}
--------------------------------------------
16) Display
--------------------------------------------
import java.io.*;
class Display
{
public static void main(String args[]){
int i;
for(i=1;i<=5;i++)
{
System.out.println("Computer\n");
}
}
}
--------------------------------------------
17) Natural
--------------------------------------------
import java.io.*;
class Natural
{
public static void main(String args[]){
int i;
for(i=1;i<=10;i++)
{
System.out.println(i);
}
}
}
--------------------------------------------
18) Exception
--------------------------------------------
import java.io.*;
class al
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
System.out.println(i);
}
}
}
--------------------------------------------
19) Factorial
--------------------------------------------
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int i,n,fact=1;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("Factorial = " + fact);
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,fact;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
fact=facto(n);
System.out.println("Factorial="+fact);
}
static int facto (int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,r,nCr,nPr;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the values of n and r to find nCr:");
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
r=Integer.parseInt(str);
nCr=facto(n)/(facto(r)*facto(n-r));
System.out.println("nCr="+nCr);
System.out.println("Enter the values of n and r to find nPr:");
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
r=Integer.parseInt(str);
nPr=facto(n)/facto(n-r);
System.out.println("nPr="+nPr);
}
static int facto (int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,fact;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n:");
str=br.readLine();
n=Integer.parseInt(str);
fact=facto(n);
System.out.println("Fatorial="+fact);
}
static int facto (int n)
{
if (n==1)
return 1;
else
return(n * facto(n-1));
}
}
--------------------------------------------
20) MultiplicationTable
--------------------------------------------
import java.io.*;
class MultiplicationTable
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=10;i++)
{
System.out.println(n + " X " +i + " = " + (n*i));
}
}
}
--------------------------------------------
21) OddNumbers
--------------------------------------------
import java.io.*;
class OddNumbers
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=2*n;i+=2)
{
System.out.println(i);
}
}
}
import java.io.*;
class OddNumbers
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i+=2)
{
System.out.println(i);
}
}
}
--------------------------------------------
22) Sum
--------------------------------------------
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum+=i;
}
System.out.println("Sum="+sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum=sum+1.0f/i;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int n,i,sum1=0,sum2=0,sum;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
sum1=sum1+a[i];
sum2=sum2+a[i]*a[i];
}
sum=sum2-sum1*sum1;
System.out.println("Sum="+sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int sum=0,n;
n=Integer.parseInt(args[0]);
while(n!=0)
{
sum=sum+(n%10)*(n%10)*(n%10);
n/=10;
}
System.out.print("Sum="+sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,fact=1;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
fact=fact*i;
sum=sum+1.0f/fact;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,sign=1;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum=sum+1.0f/i*sign;
sign=sign*-1;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum{
public static void main(String args[]) throws IOException{
int m,n,i,j;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of rows and columns:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
int a[][]=new int [m][n];
int b[][]=new int [m][n];
int c[][]=new int [m][n];
System.out.println("Matrix A");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
System.out.println("Matrix B");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
b[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("Sum Matrix");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int n,sum;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n:");
str=br.readLine();
n=Integer.parseInt(str);
sum=series(n);
System.out.println("Sum="+sum);
}
static int series(int n)
{
if (n==1)
return 1;
else
return(n + series(n-1));
}
}
--------------------------------------------
23) Even
--------------------------------------------
import java.io.*;
class Even
{
public static void main(String args[]) throws IOException{
int i,n,sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=2;i<=2*n;i+=2)
{
System.out.println(i);
}
}
}
import java.io.*;
class Sine
{
public static void main(String args[]) throws IOException{
int i,sign=-1,fact=1;
double x,sum,num,term;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter angle in degrees:");
str= br.readLine();
x=Double.parseDouble(str);
x=x*3.14159/180;
sum=term=x;
for(i=3;term>=0.0000001;i++)
{
fact=fact*i*(i-1);
num=Math.pow(x,i);
term=num/fact;
sum=sum+num/fact*sign;
sign=sign*-1;
}
System.out.println("Sum=" + sum);
}
}
--------------------------------------------
26) Simple
--------------------------------------------
import java.io.*;
class Simple
{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=2;j++)
{
System.out.print("Hi\t");
}
System.out.println();
}
}
}
--------------------------------------------
27) Pattern
--------------------------------------------
import java.io.*;
class Pattern{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("1");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the largest line:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the largest line:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the upper half:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.print("*");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print((char)(j+64));
}
for(j=i-1;j>=1;j--)
{
System.out.print((char)(j+64));
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n,k;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1,k=1;i<=n;i++)
{
for(j=1;j<=i;j++,k++)
{
System.out.print(k+" ");
}
System.out.println();
}
}
}
--------------------------------------------
28) Natural
--------------------------------------------
import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException{
int i,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
i=1;
while(i<=n)
{
System.out.println(i);
i++;
}
}
}
import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException{
int i,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
i=1;
do
{
System.out.println(i);
i++;
}while(i<=n);
}
}
--------------------------------------------
29) Digits
--------------------------------------------
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int sum=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
sum+=n%10;
n/=10;
}
System.out.println("Sum="+sum);
}
}
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int count=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
count++;
n/=10;
}
System.out.println("Count="+count);
}
}
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int n,sum;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
sum=add(n);
System.out.println("Sum of Digits="+sum);
}
static int add(int n)
{
if (n==0)
return 0;
else
return(n%10 + add(n/10));
}
}
--------------------------------------------
30) Reverse
--------------------------------------------
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int rev=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
rev=rev*10+n%10;
n/=10;
}
System.out.println("Reverse No="+rev);
}
}
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int rev=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
rev=rev*10+n%10;
n/=10;
}
while(rev!=0)
{
System.out.print(rev%10+ " ");
rev/=10;
}
}
}
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int n,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
int b[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
b[n-i-1]=a[i];
}
for(i=0;i<=n-1;i++)
{
System.out.println(b[i]);
}
}
}
--------------------------------------------
31) Divisible
--------------------------------------------
import java.io.*;
class Divisible
{
public static void main(String args[]) throws IOException{
int sum=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
if(n%10==0)
System.out.println("Divisible by 10");
else
System.out.println("Not divisible by 10");
}
}
--------------------------------------------
32) Prime Number
--------------------------------------------
import java.io.*;
class Prime
{
public static void main(String args[]) throws IOException{
int sum=0,n,i=2;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n%i!=0)
{
i++;
}
if(n==i)
{
System.out.println("Prime Number");
}
else
{
System.out.println("Not a prime number");
}
}
}
import java.io.*;
class Prime
{
public static void main(String args[]) throws IOException{
int n,i,x=2;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
x++;
i=2;
while(x%i!=0)
{
i++;
}
if(x==i)
{
System.out.println(x);
n--;
}
}
}
}
import java.io.*;
class al
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
System.out.println(i);
}
}
}
--------------------------------------------
19) Factorial
--------------------------------------------
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int i,n,fact=1;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("Factorial = " + fact);
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,fact;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
fact=facto(n);
System.out.println("Factorial="+fact);
}
static int facto (int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,r,nCr,nPr;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the values of n and r to find nCr:");
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
r=Integer.parseInt(str);
nCr=facto(n)/(facto(r)*facto(n-r));
System.out.println("nCr="+nCr);
System.out.println("Enter the values of n and r to find nPr:");
str=br.readLine();
n=Integer.parseInt(str);
str=br.readLine();
r=Integer.parseInt(str);
nPr=facto(n)/facto(n-r);
System.out.println("nPr="+nPr);
}
static int facto (int n)
{
int i,fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
return fact;
}
}
import java.io.*;
class Factorial
{
public static void main(String args[]) throws IOException{
int n,fact;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n:");
str=br.readLine();
n=Integer.parseInt(str);
fact=facto(n);
System.out.println("Fatorial="+fact);
}
static int facto (int n)
{
if (n==1)
return 1;
else
return(n * facto(n-1));
}
}
--------------------------------------------
20) MultiplicationTable
--------------------------------------------
import java.io.*;
class MultiplicationTable
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=10;i++)
{
System.out.println(n + " X " +i + " = " + (n*i));
}
}
}
--------------------------------------------
21) OddNumbers
--------------------------------------------
import java.io.*;
class OddNumbers
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=2*n;i+=2)
{
System.out.println(i);
}
}
}
import java.io.*;
class OddNumbers
{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i+=2)
{
System.out.println(i);
}
}
}
--------------------------------------------
22) Sum
--------------------------------------------
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum+=i;
}
System.out.println("Sum="+sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum=sum+1.0f/i;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int n,i,sum1=0,sum2=0,sum;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
sum1=sum1+a[i];
sum2=sum2+a[i]*a[i];
}
sum=sum2-sum1*sum1;
System.out.println("Sum="+sum);
}
}
class Sum
{
public static void main(String args[]) throws IOException{
int sum=0,n;
n=Integer.parseInt(args[0]);
while(n!=0)
{
sum=sum+(n%10)*(n%10)*(n%10);
n/=10;
}
System.out.print("Sum="+sum);
}
}
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,fact=1;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
fact=fact*i;
sum=sum+1.0f/fact;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int i,n,sign=1;
float sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
sum=sum+1.0f/i*sign;
sign=sign*-1;
}
System.out.println("Sum=" + sum);
}
}
import java.io.*;
class Sum{
public static void main(String args[]) throws IOException{
int m,n,i,j;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of rows and columns:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
int a[][]=new int [m][n];
int b[][]=new int [m][n];
int c[][]=new int [m][n];
System.out.println("Matrix A");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
System.out.println("Matrix B");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
b[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("Sum Matrix");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}
import java.io.*;
class Sum
{
public static void main(String args[]) throws IOException{
int n,sum;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n:");
str=br.readLine();
n=Integer.parseInt(str);
sum=series(n);
System.out.println("Sum="+sum);
}
static int series(int n)
{
if (n==1)
return 1;
else
return(n + series(n-1));
}
}
--------------------------------------------
23) Even
--------------------------------------------
import java.io.*;
class Even
{
public static void main(String args[]) throws IOException{
int i,n,sum=0;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
for(i=2;i<=2*n;i+=2)
{
System.out.println(i);
}
}
}
--------------------------------------------
24) Fibonacci
--------------------------------------------
import java.io.*;
class Fibonacci
{
public static void main(String args[]) throws IOException{
int i,n,a,b,c;
a=0;
b=1;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter the value of n:");
str= br.readLine();
n=Integer.parseInt(str);
System.out.println("Fibonacci Series:\n0\n1");
for(i=1;i<=n-2;i++)
{
c=a+b;
System.out.println(c);
a=b;
b=c;
}
}
}
import java.io.*;
class Fibonacci{
public static void main(String args[]) throws IOException{
int i,n;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of n:");
str=br.readLine();
n=Integer.parseInt(str);
System.out.println("Fibonacci Series\n0");
for(i=1;i<=n-1;i++)
{
System.out.println(fibo(0,1,i));
}
}
static int fibo(int a, int b, int i)
{
if (i==1)
return b;
else
return(fibo(b,(a+b),(i-1)));
}
}
--------------------------------------------
25) Sine
--------------------------------------------
class Sine
{
public static void main(String args[]) throws IOException{
int i,sign=-1,fact=1;
double x,sum,num,term;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.print("Enter angle in degrees:");
str= br.readLine();
x=Double.parseDouble(str);
x=x*3.14159/180;
sum=term=x;
for(i=3;term>=0.0000001;i++)
{
fact=fact*i*(i-1);
num=Math.pow(x,i);
term=num/fact;
sum=sum+num/fact*sign;
sign=sign*-1;
}
System.out.println("Sum=" + sum);
}
}
--------------------------------------------
26) Simple
--------------------------------------------
import java.io.*;
class Simple
{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=2;j++)
{
System.out.print("Hi\t");
}
System.out.println();
}
}
}
--------------------------------------------
27) Pattern
--------------------------------------------
import java.io.*;
class Pattern{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("1");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the largest line:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the largest line:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of * in the upper half:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.print("*");
}
System.out.println();
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=2*i-1;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print((char)(j+64));
}
for(j=i-1;j>=1;j--)
{
System.out.print((char)(j+64));
}
System.out.println();
}
}
}
import java.io.*;
class Pattern
{
public static void main(String args[]) throws IOException{
int i,j,n,k;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
for(i=1,k=1;i<=n;i++)
{
for(j=1;j<=i;j++,k++)
{
System.out.print(k+" ");
}
System.out.println();
}
}
}
--------------------------------------------
28) Natural
--------------------------------------------
import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException{
int i,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
i=1;
while(i<=n)
{
System.out.println(i);
i++;
}
}
}
import java.io.*;
class Natural
{
public static void main(String args[]) throws IOException{
int i,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of lines:");
str=br.readLine();
n=Integer.parseInt(str);
i=1;
do
{
System.out.println(i);
i++;
}while(i<=n);
}
}
--------------------------------------------
29) Digits
--------------------------------------------
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int sum=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
sum+=n%10;
n/=10;
}
System.out.println("Sum="+sum);
}
}
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int count=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
count++;
n/=10;
}
System.out.println("Count="+count);
}
}
import java.io.*;
class Digits
{
public static void main(String args[]) throws IOException{
int n,sum;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
sum=add(n);
System.out.println("Sum of Digits="+sum);
}
static int add(int n)
{
if (n==0)
return 0;
else
return(n%10 + add(n/10));
}
}
--------------------------------------------
30) Reverse
--------------------------------------------
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int rev=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
rev=rev*10+n%10;
n/=10;
}
System.out.println("Reverse No="+rev);
}
}
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int rev=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
rev=rev*10+n%10;
n/=10;
}
while(rev!=0)
{
System.out.print(rev%10+ " ");
rev/=10;
}
}
}
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int n,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
int b[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
b[n-i-1]=a[i];
}
for(i=0;i<=n-1;i++)
{
System.out.println(b[i]);
}
}
}
import java.io.*;
class Reverse
{
public static void main(String args[]) throws IOException{
int n,i,temp;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=(n-1)/2;i++)
{
temp=a[n-i-1];
a[n-1-i]=a[i];
a[i]=temp;
}
for(i=0;i<=n-1;i++)
{
System.out.println(a[i]);
}
}
}
31) Divisible
--------------------------------------------
import java.io.*;
class Divisible
{
public static void main(String args[]) throws IOException{
int sum=0,n;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
if(n%10==0)
System.out.println("Divisible by 10");
else
System.out.println("Not divisible by 10");
}
}
--------------------------------------------
32) Prime Number
--------------------------------------------
import java.io.*;
class Prime
{
public static void main(String args[]) throws IOException{
int sum=0,n,i=2;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n%i!=0)
{
i++;
}
if(n==i)
{
System.out.println("Prime Number");
}
else
{
System.out.println("Not a prime number");
}
}
}
import java.io.*;
class Prime
{
public static void main(String args[]) throws IOException{
int n,i,x=2;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
while(n!=0)
{
x++;
i=2;
while(x%i!=0)
{
i++;
}
if(x==i)
{
System.out.println(x);
n--;
}
}
}
}
--------------------------------------------
33) Armstrong
--------------------------------------------
import java.io.*;
class Armstrong
{
public static void main(String args[]) throws IOException{
int sum=0,digit,n,copy;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter a number:");
str=br.readLine();
n=Integer.parseInt(str);
copy=n;
while(n!=0)
{
digit=n%10;
sum+=digit*digit*digit;
n/=10;
}
if(copy==sum)
System.out.println("Armstrongs Number");
else
System.out.println("Not Armstrongs Number");
}
}
--------------------------------------------
34) Leap
--------------------------------------------
import java.io.*;
class Leap{
public static void main(String args[]) throws IOException{
int year;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter year:");
str=br.readLine();
year=Integer.parseInt(str);
if(year%4==0 && year%100!=0 || year%100==0 && year%400==0)
System.out.println("Leap Year");
else
System.out.println("Not Leap Year");
}
}
--------------------------------------------
35) Grade
--------------------------------------------
import java.io.*;
class Grade
{
public static void main(String args[]) throws IOException{
int marks;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter marks:");
str=br.readLine();
marks=Integer.parseInt(str);
if(marks>=70)
{
System.out.println("Distinction");
}
else
{
if (marks>60)
{
System.out.println("First Class");
}
else
{
if (marks>50)
{
System.out.println("Second Class");
}
else
{
if(marks>40)
{
System.out.println("Pass Class");
}
else
{
System.out.println("Fail");
}
}
}
}
}
}
import java.io.*;
class Grade
{
public static void main(String args[]) throws IOException{
int marks;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter marks out of 100:");
str=br.readLine();
marks=Integer.parseInt(str);
if(marks==100)
System.out.println("Distinction");
else
switch(marks/10)
{
case 0:
case 1:
case 2:
case 3:System.out.println("Fail");
break;
case 4:System.out.println("Pass Class");
break;
case 5:System.out.println("Second Class");
break;
case 6:System.out.println("First Class");
break;
case 7:
case 8:
case 9:System.out.println("Distinction");
break;
default:System.out.println("Invalid Marks");
}
}
}
--------------------------------------------
36) Menu
--------------------------------------------
import java.io.*;
class Menu{
public static void main(String args[]) throws IOException{
int choice,a,b;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Modulus\nEnter your choice:");
str=br.readLine();
choice=Integer.parseInt(str);
System.out.print("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
switch(choice)
{
case 1:System.out.println("Sum="+(a+b));
break;
case 2:System.out.println("Difference="+(a-b));
break;
case 3:System.out.println("Product="+(a*b));
break;
case 4:System.out.println("Quotient="+(a/b));
break;
case 5:System.out.println("Remainder="+(a%b));
break;
default:System.out.println("Invalid Choice");
}
}
}
--------------------------------------------
37) Month
------------------------------------------
import java.io.*;
class Month
{
public static void main(String args[]) throws IOException{
int month;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter month no.:");
str=br.readLine();
month=Integer.parseInt(str);
switch(month)
{
case 1:System.out.println("January");
break;
case 2:System.out.println("February");
break;
case 3:System.out.println("March");
break;
case 4:System.out.println("April");
break;
case 5:System.out.println("May");
break;
case 6:System.out.println("June");
break;
case 7:System.out.println("July");
break;
case 8:System.out.println("August");
break;
case 9:System.out.println("September");
break;
case 10:System.out.println("October");
break;
case 11:System.out.println("November");
break;
case 12:System.out.println("December");
break;
default:System.out.println("Invalid Month no.");
}
}
}
--------------------------------------------
38) Break
--------------------------------------------
import java.io.*;
class Break
{
public static void main(String args[]) throws IOException{
int n,total=0,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
for(i=1;i<=10;i++)
{
System.out.print("Enter a no.:");
str=br.readLine();
n=Integer.parseInt(str);
if(n>99)
break;
total+=n;
}
System.out.println("Sum="+total);
}
}
--------------------------------------------
39) Continue
--------------------------------------------
import java.io.*;
class Continue
{
public static void main(String args[]) throws IOException{
int n,total=0,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
for(i=1;i<=5;i++)
{
System.out.print("Enter a no.:");
str=br.readLine();
n=Integer.parseInt(str);
if(n>99)
{
System.out.println("Number is greater than 99");
i--;
continue;
}
total+=n;
}
System.out.println("Sum="+total);
}
}
--------------------------------------------
40) GCD
--------------------------------------------
import java.io.*;
class GCD
{
public static void main(String args[]) throws IOException{
int n1,n2,gcd;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter two nos.:");
str=br.readLine();
n1=Integer.parseInt(str);
str=br.readLine();
n2=Integer.parseInt(str);
if (n1<n2)
gcd=n1;
else gcd=n2;
while(n1%gcd!=0 || n2%gcd!=0)
{
gcd--;
}
if(gcd==1)
System.out.println("GCD doesn't exists");
else
System.out.println("GCD=" + gcd);
}
}
--------------------------------------------
41) LCM
--------------------------------------------
import java.io.*;
class LCM{
public static void main(String args[]) throws IOException{
int n1,n2,lcm;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter two nos.:");
str=br.readLine();
n1=Integer.parseInt(str);
str=br.readLine();
n2=Integer.parseInt(str);
if (n1<n2)
lcm=n2;
else lcm=n1;
while(lcm%n1!=0 || lcm%n2!=0)
{
lcm++;
}
System.out.println("LCM=" + lcm);
}
}
--------------------------------------------
42) Array
--------------------------------------------
import java.io.*;
class Array
{
public static void main(String args[]) throws IOException{
int n,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
System.out.println(a[i]);
}
}
}
--------------------------------------------
43) Average
--------------------------------------------
import java.io.*;
class Average
{
public static void main(String args[]) throws IOException{
int n,i,sum=0;
float avg;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
sum=sum+a[i];
}
avg=(float)sum/n;
System.out.println("Average="+avg);
}
}
--------------------------------------------
44) SD
--------------------------------------------
import java.io.*;
class SD
{
public static void main(String args[]) throws IOException{
int n,i;
float avg,sum=0,sd;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-1;i++)
{
sum=sum+a[i];
}
avg=sum/n;
sum=0;
for(i=0;i<=n-1;i++)
{
sum=sum+(a[i]-avg)*(a[i]-avg);
}
sum=sum/n;
sd=(float)Math.pow(sum,0.5);
System.out.println("SD="+sd);
}
}
--------------------------------------------
45) Line
--------------------------------------------
import java.io.*;
class Line
{
public static void main(String args[]) throws IOException{
int n,i,xi=0,yi=0,xiyi=0,xi2=0;
float m,c;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of points:");
str=br.readLine();
n=Integer.parseInt(str);
int x[]=new int [n];
int y[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter x co-ordinate:");
str=br.readLine();
x[i]=Integer.parseInt(str);
System.out.print("Enter y co-ordinate:");
str=br.readLine();
y[i]=Integer.parseInt(str);
}
for(i=0;i<=(n-1);i++)
{
xi=xi+x[i];
yi=yi+y[i];
xiyi=xiyi+x[i]*y[i];
xi2=xi2+x[i]*x[i];
}
m=(float)(n*xiyi-xi*yi)/(n*xi2-yi*yi);
c=(yi-m*xi)/n;
System.out.println("Equation of straight line is y="+m+"x+"+c);
}
}
--------------------------------------------
46) Large
--------------------------------------------
import java.io.*;
class Large{
public static void main(String args[]) throws IOException{
int n,i,large;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
large=a[0];
for(i=0;i<=n-1;i++)
{
if(large<a[i])
large=a[i];
}
System.out.println("Largest no="+large);
}
}
--------------------------------------------
47) Small
--------------------------------------------
import java.io.*;
class Small
{
public static void main(String args[]) throws IOException{
int n,i,small;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
small=a[0];
for(i=0;i<=n-1;i++)
{
if(small>a[i])
small=a[i];
}
System.out.println("Smallest no="+small);
}
}
--------------------------------------------
48) Search
--------------------------------------------
import java.io.*;
class Search
{
public static void main(String args[]) throws IOException{
int n,i,search;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
System.out.print("Enter the no to be searched:");
str=br.readLine();
search=Integer.parseInt(str);
for(i=0;i<=(n-1);i++)
{
if(search==a[i])
break;
}
if(i==n)
System.out.println("No. not found");
else
System.out.println("Index =" + i);
}
}
--------------------------------------------
49) Ascending
--------------------------------------------
import java.io.*;
class Ascend
{
public static void main(String args[]) throws IOException{
int n,i,j,temp;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-2;i++)
{
for(j=0;j<=n-2;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("After Sorting");
for(i=0;i<=n-1;i++)
{
System.out.println(a[i]);
}
}
}
--------------------------------------------
50) Descending
--------------------------------------------
import java.io.*;
class Descend
{
public static void main(String args[]) throws IOException{
int n,i,j,temp;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
for(i=0;i<=n-2;i++)
{
for(j=0;j<=n-2;j++)
{
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("After Sorting");
for(i=0;i<=n-1;i++)
{
System.out.println(a[i]);
}
}
}
--------------------------------------------
51) Matrix
--------------------------------------------
import java.io.*;
class Matrix
{
public static void main(String args[]) throws IOException{
int m,n,i,j;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of rows and columns:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
int a[][]=new int [m][n];
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
}
--------------------------------------------
52) Diagonal
--------------------------------------------
import java.io.*;
class Diagonal
{
public static void main(String args[]) throws IOException{
int m,n,i,j,sum=0;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter no of rows and columns:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
int a[][]=new int [m][n];
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(i==j)
sum=sum+a[i][j];
}
}
System.out.println("Sum="+sum);
}
}
--------------------------------------------
53) Transpose
--------------------------------------------
import java.io.*;
class Transpose{
public static void main(String args[]) throws IOException{
int m,n,i,j;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter values of m and n:");
str=br.readLine();
m=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
int a[][]=new int [m][n];
int b[][]=new int [n][m];
System.out.println("Matrix A");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
b[j][i]=a[i][j];
}
}
System.out.println("Transpose Matrix");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println();
}
}
}
import java.io.*;
class Transpose
{
public static void main(String args[]) throws IOException{
int m,i,j,temp;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter value of m:");
str=br.readLine();
m=Integer.parseInt(str);
int a[][]=new int [m][m];
for(i=0;i<=m-1;i++)
{
for(j=0;j<=m-1;j++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i][j]=Integer.parseInt(str);
}
}
for(i=0;i<=m-1;i++)
{
for(j=i;j<=m-1;j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
System.out.println("Transpose Matrix");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=m-1;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
}
--------------------------------------------
54) Exam
--------------------------------------------
import java.io.*;
class Exam
{
public static void main(String args[]) throws IOException{
int i,j,largeroll,largetotal;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
int a[][]=new int [5][5];
for(i=0;i<=4;i++)
{
System.out.print("Enter roll no and marks in three subjects:");
str=br.readLine();
a[i][0]=Integer.parseInt(str);
str=br.readLine();
a[i][1]=Integer.parseInt(str);
str=br.readLine();
a[i][2]=Integer.parseInt(str);
str=br.readLine();
a[i][3]=Integer.parseInt(str);
a[i][4]=a[i][1]+a[i][2]+a[i][3];
}
System.out.println("Roll NO\tSub 1\tSub 2\tSub 3\tTotal\n");
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
largeroll=a[0][0];
largetotal=a[0][4];
for(i=0;i<=4;i++)
{
if(a[i][4]>largetotal)
{
largeroll=a[i][0];
largetotal=a[i][4];
}
}
System.out.println("Highest total marks is:" +largetotal +" and obtained by student with roll number:"+largeroll);
}
}
--------------------------------------------
55) Arraycopy
--------------------------------------------
import java.io.*;
class ArrayCopy
{
public static void main(String args[]) throws IOException{
int n,i;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter number of elements:");
str=br.readLine();
n=Integer.parseInt(str);
int a[]=new int [n];
int b[]=new int [n];
for(i=0;i<=n-1;i++)
{
System.out.print("Enter a no:");
str=br.readLine();
a[i]=Integer.parseInt(str);
}
System.arraycopy(a,0,b,0,a.length);
for(i=0;i<=n-1;i++)
{
System.out.print(b[i]+"\t");
}
System.out.println();
System.arraycopy(a,0,b,1,a.length-1);
for(i=0;i<=n-1;i++)
{
System.out.print(b[i]+"\t");
}
System.out.println();
System.arraycopy(a,1,b,0,a.length-1);
for(i=0;i<=n-1;i++)
{
System.out.print(b[i]+"\t");
}
}
}
--------------------------------------------
56) Uppercase
--------------------------------------------
import java.io.*;
class UpperCase
{
public static void main(String args[]) throws IOException{
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
str=str.toUpperCase();
System.out.println(str);
}
}
--------------------------------------------
57) Titlecase
--------------------------------------------
import java.io.*;
class TitleCase
{
public static void main(String args[]) throws IOException{
String str,str1,str2;
int i,n;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
str=str.toLowerCase();
str1=str.substring(1);
str=str.substring(0,1);
str=str.toUpperCase();
str=str.concat(str1);
n=str.length();
for(i=0;i<=n-1;i++)
{
if(str.charAt(i)==' ')
{
str1=str.substring(0,i+1);
str2=str.substring(i+2);
str=str.substring(i+1,i+2);
str=str.toUpperCase();
str=str1.concat(str);
str=str.concat(str2);
}
}
System.out.println(str);
}
}
--------------------------------------------
58) SentenceCase
--------------------------------------------
import java.io.*;
class SentenceCase
{
public static void main(String args[]) throws IOException{
String str,str1,str2;
int i,n;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
str=str.toLowerCase();
str1=str.substring(1);
str=str.substring(0,1);
str=str.toUpperCase();
str=str.concat(str1);
n=str.length();
System.out.println(str);
}
}
--------------------------------------------
59) Days
--------------------------------------------
import java.io.*;
class Days
{
public static void main(String args[]) throws IOException{
String str,str1;
int sd,sm,sy,ed,em,ey,i,total;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter the Starting date of the semester (MM/DD/YYYY):");
str=br.readLine();
str1=str.substring(0,2);
sm=Integer.parseInt(str1);
str1=str.substring(3,5);
sd=Integer.parseInt(str1);
str1=str.substring(6,10);
sy=Integer.parseInt(str1);
System.out.println("Enter the ending date of the semester (MM/DD/YYYY):");
str=br.readLine();
str1=str.substring(0,2);
em=Integer.parseInt(str1);
str1=str.substring(3,5);
ed=Integer.parseInt(str1);
str1=str.substring(6,10);
ey=Integer.parseInt(str1);
total=ed;
for(i=sm;i<=em-2;i++)
{
total+=days[i];
}
total+=days[sm-1]-sd+1;
if((sy%4==0 && sy%100!=0 && sm<=2 && em>2) || (sy%100==0 && sy%400==0 && sm<=2 && em>2))
total++;
System.out.println("Total Days="+total);
}
}
--------------------------------------------
60) CharArray
--------------------------------------------
import java.io.*;
class CharArray
{
public static void main(String args[]) throws IOException{
String str;
int i,n;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
n=str.length();
char c[]=new char[n];
c=str.toCharArray();
for(i=0;i<=n-1;i++)
{
System.out.println(i+"\t"+c[i]);
}
}
}
--------------------------------------------
61) Vowels
--------------------------------------------
import java.io.*;
class Vowels
{
public static void main(String args[]) throws IOException{
String str;
int count=0,i,n;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
n=str.length();
char c[]=new char[n];
c=str.toCharArray();
for(i=0;i<=n-1;i++)
{
if(c[i]=='a' || c[i]=='e' || c[i]=='i' || c[i]=='o' || c[i]=='u' || c[i]=='A' || c[i]=='E' || c[i]=='I' || c[i]=='O' || c[i]=='U')
count++;
}
System.out.println(count+" Vowels");
}
}
--------------------------------------------
62) Count
--------------------------------------------
import java.io.*;
class Count
{
public static void main(String args[]) throws IOException{
String str;
int countv=0,i,n,countd=0,counts=0,countc=0;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
n=str.length();
char c[]=new char[n];
c=str.toCharArray();
for(i=0;i<=n-1;i++)
{
if(c[i]=='a' || c[i]=='e' || c[i]=='i' || c[i]=='o' || c[i]=='u' || c[i]=='A' || c[i]=='E' || c[i]=='I' || c[i]=='O' || c[i]=='U')
countv++;
else if(c[i]==' ')
counts++;
else if(c[i]>='0' && c[i]<='9')
countd++;
else if((c[i]>='a' && c[i]<='z') || (c[i]>='A' && c[i]<='Z'))
countc++;
}
System.out.println(countv+" Vowels\n"+counts+" spaces\n"+countd+" Digits\n"+countc+" Consonants");
}
}
import java.io.*;
class Count
{
public static void main(String args[]) throws IOException{
String str;
int countu=0,i,n,countd=0,counts=0,countl=0;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
n=str.length();
char c[]=new char[n];
c=str.toCharArray();
for(i=0;i<=n-1;i++)
{
if(c[i]>='A' && c[i]<='Z')
countu++;
else if(c[i]==' ')
counts++;
else if(c[i]>='0' && c[i]<='9')
countd++;
else if(c[i]>='a' && c[i]<='z')
countl++;
}
System.out.println(countu+" Upper case alphabets\n"+counts+" spaces\n"+countd+" Digits\n"+countl+" Lower case alphabets");
}
}
--------------------------------------------
63)Palindrome
--------------------------------------------
import java.io.*;
class Palindrome{
public static void main(String args[]) throws IOException{
String str;
int i,n;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
n=str.length();
char c[]=new char[n];
char rev[]=new char[n];
c=str.toCharArray();
for(i=0;i<=n-1;i++)
{
rev[n-i-1]=c[i];
}
for(i=0;i<=n-1;i++)
{
if(rev[i]!=c[i])
break;
}
if(n==i)
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
import java.io.*;
class Palindrome
{
public static void main(String args[]) throws IOException{
String str,rev;
StringBuffer str1=new StringBuffer();
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a String:");
str=br.readLine();
str1.append(str);
str1.reverse();
rev=str1.toString();
if(str.equalsIgnoreCase(rev))
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
--------------------------------------------
64) Vector Demonstration
--------------------------------------------
import java.util.*;
class VectorDemo
{
public static void main(String args[]) {
Vector v = new Vector(5,3);
System.out.println("Initial size: " + v.size());
System.out.println("Initial capacity: " +v.capacity());
v.addElement(new Integer(4));
v.addElement(new Integer(9));
v.addElement(new Integer(3));
System.out.println("Capacity: " +v.capacity());
v.addElement(new Double(3.25));
System.out.println("Current capacity: " +v.capacity());
v.addElement(new Double(5.25));
System.out.println("Current capacity: " +v.capacity());
v.addElement(new Double(4.25));
System.out.println("Current capacity: " +v.capacity());
}
}
--------------------------------------------
65) Student
--------------------------------------------
import java.util.*;
class Student
{
public static void main(String args[]) {
Vector v = new Vector();
int i,n;
n=args.length;
for(i=0;i<=n-1;i++)
{
v.addElement(args[i]);
}
for(i=0;i<=n-1;i++)
{
System.out.println(v.elementAt(i));
}
}
}
import java.util.*;
import java.io.*;
class Student
{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
Vector v = new Vector();
int i,choice=0;
System.out.println("Enter 5 names:");
for(i=0;i<=4;i++)
{
str=br.readLine();
v.addElement(str);
}
while(choice!=4)
{
System.out.println("1.Add new name\n2.Delete name\n3.Display name\n4. Exit\nEnter your choice:");
str=br.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1: System.out.println("Enter name:");
str=br.readLine();
v.addElement(str);
break;
case 2: System.out.println("Enter name:");
str=br.readLine();
v.removeElement(str);
break;
case 3: System.out.println("Enter index:");
str=br.readLine();
i=Integer.parseInt(str);
System.out.println("Name:"+v.elementAt(i));
break;
case 4: break;
default: System.out.println("Invalid choice");
}
System.out.println("Current List:");
for(i=0;i<=v.size()-1;i++)
{
System.out.println(v.elementAt(i));
}
}
}
}
import java.io.*;
class Student
{
private int id,p,c,m,t;
private String name;
void accept() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
String str;
System.out.println("Enter name, ID and marks in P, C & M");
name=br.readLine();
str=br.readLine();
id=Integer.parseInt(str);
str=br.readLine();
p=Integer.parseInt(str);
str=br.readLine();
c=Integer.parseInt(str);
str=br.readLine();
m=Integer.parseInt(str);
t=p+c+m;
}
void display()
{
System.out.println("Name:"+name+"\nID:"+id+"\nP:"+p+"\nC:"+c+"\nM:"+m+"\nT:"+t);
}
}
class Main{
public static void main(String args[]) throws IOException{
Student s= new Student();
s.accept();
s.display();
}
}
--------------------------------------------
66) Shopping
--------------------------------------------
import java.util.*;
import java.io.*;
class Shopping
{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
Vector v = new Vector();
int i,choice=0;
System.out.println("Enter 5 items:");
for(i=0;i<=4;i++)
{
str=br.readLine();
v.addElement(str);
}
while(choice!=4)
{
System.out.println("1.Add new item\n2.Delete item\n3.Display item\n4. Exit\nEnter your choice:");
str=br.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1: System.out.println("Enter name:");
str=br.readLine();
v.addElement(str);
break;
case 2: System.out.println("Enter name:");
str=br.readLine();
v.removeElement(str);
break;
case 3: System.out.println("Enter index:");
str=br.readLine();
i=Integer.parseInt(str);
System.out.println("Name:"+v.elementAt(i));
break;
case 4: break;
default: System.out.println("Invalid choice");
}
System.out.println("Current List:");
for(i=0;i<=v.size()-1;i++)
{
System.out.println(v.elementAt(i));
}
}
}
}
--------------------------------------------
67) Add
--------------------------------------------
import java.io.*;
class Add
{
public static void main(String args[]) throws IOException{
int a,b,sum;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
sum=add(a,b);
System.out.println("Sum="+sum);
}
static int add (int x, int y)
{
return(x+y);
}
}
import java.io.*;
class Add
{
public static void main(String args[]) throws IOException{
int a,b;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
add(a,b);
}
static void add (int x, int y)
{
System.out.println("Sum="+(x+y));
}
}
--------------------------------------------
68) Power
--------------------------------------------
import java.io.*;
class Power{
public static void main(String args[]) throws IOException{
int x,n,y;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String str;
System.out.println("Enter the value of x and n:");
str=br.readLine();
x=Integer.parseInt(str);
str=br.readLine();
n=Integer.parseInt(str);
y=pow(x,n);
System.out.println("Ans="+y);
}
static int pow(int x, int n)
{
if (n==1)
return x;
else
return(x * pow(x,n-1));
}
}
--------------------------------------------
69) Circle
--------------------------------------------
import java.io.*;
class Circle{
private float r,area;
void accept(float x)
{
r=x;
}
void calculate()
{
area=3.14f*r*r;
}
void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main(String args[]) throws IOException{
float x;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Radius:");
str=br.readLine();
x=Float.parseFloat(str);
Circle c=new Circle();
c.accept(x);
c.calculate();
c.display();
}
}
--------------------------------------------
70) Euclid
--------------------------------------------
import java.io.*;
class Euclid{
private int n1,n2,gcd;
void accept(int x, int y)
{
n1=x;
n2=y;
}
void calculate()
{
int temp;
while(n1%n2!=0)
{
n1=n1%n2;
temp=n1;
n1=n2;
n2=temp;
}
gcd=n2;
}
void display()
{
System.out.println("GCD="+gcd);
}
}
class Main{
public static void main(String args[]) throws IOException{
int x,y;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter two numbers:");
str=br.readLine();
x=Integer.parseInt(str);
str=br.readLine();
y=Integer.parseInt(str);
Euclid e=new Euclid();
e.accept(x,y);
e.calculate();
e.display();
}
}
import java.io.*;
class Euclid
{
private int n1,n2,gcd;
Euclid(int x, int y)
{
n1=x;
n2=y;
}
void calculate()
{
int temp;
while(n1%n2!=0)
{
n1=n1%n2;
temp=n1;
n1=n2;
n2=temp;
}
gcd=n2;
}
void display()
{
System.out.println("GCD="+gcd);
}
}
class Main{
public static void main(String args[]) throws IOException{
int x,y;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter two numbers:");
str=br.readLine();
x=Integer.parseInt(str);
str=br.readLine();
y=Integer.parseInt(str);
Euclid e=new Euclid(x,y);
e.calculate();
e.display();
}
}
--------------------------------------------
71) Employee
--------------------------------------------
import java.io.*;
class Employee{
private int empid;
private float salary;
private String empname,designation;
void get_employee() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
String str;
System.out.println("Enter employee name, designation, ID and salary");
empname=br.readLine();
designation=br.readLine();
str=br.readLine();
empid=Integer.parseInt(str);
str=br.readLine();
salary=Float.parseFloat(str);
}
void show_grade()
{
if(salary<10000)
System.out.println("Grade D");
else if(salary<25000)
System.out.println("Grade C");
else if(salary<50000)
System.out.println("Grade B");
else
System.out.println("Grade A");
}
void show_employee()
{
System.out.println("Name:"+empname+"\nDesignation:"+designation+"\nID:"+empid+"\nSalary:"+salary);
}
}
class Main{
public static void main(String args[]) throws IOException{
Employee e= new Employee();
e.get_employee();
e.show_grade();
e.show_employee();
}
}
--------------------------------------------
72) Counter
--------------------------------------------
import java.io.*;
class Counter
{
private static int count;
Counter()
{
count++;
}
static void display()
{
System.out.println("Count="+count);
}
}
class Main{
public static void main(String args[]) throws IOException{
Counter c1=new Counter();
Counter.display();
Counter c2=new Counter();
Counter c3=new Counter();
Counter.display();
Counter c4=new Counter();
Counter c5=new Counter();
Counter.display();
}
}
--------------------------------------------
73) Compare
--------------------------------------------
import java.io.*;
class Compare
{
private int x;
Compare(int a)
{
x=a;
}
Compare compare (Compare c)
{
if(x>c.x)
return this;
else
return c;
}
void display()
{
System.out.println("x="+x);
}
}
class Main{
public static void main(String args[]) throws IOException{
int a;
String str;
BufferedReader br= new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter a no:");
str=br.readLine();
a=Integer.parseInt(str);
Compare c1=new Compare(a);
System.out.println("Enter another no:");
str=br.readLine();
a=Integer.parseInt(str);
Compare c2=new Compare(a);
Compare c3;
c3=c1.compare(c2);
c3.display();
}
}
--------------------------------------------
74) Bank, Deposit, Withdraw
--------------------------------------------
import java.util.*;
import java.io.*;
class Bank{
String name;
float acc_no,balance;
void accept(String str, float no, float bal)
{
name=str;
acc_no=no;
balance=bal;
}
public String toString()
{
return(name+"\t"+acc_no+"\t"+balance);
}
}
class Withdraw{
String date;
float acc_no,amount;
void accept(String str, float no, float amt)
{
date=str;
acc_no=no;
amount=amt;
}
}
class Deposit{
String date;
float acc_no,amount;
void accept(String str, float no, float amt)
{
date=str;
acc_no=no;
amount=amt;
}
}
class Main{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str,str1;
Vector bank = new Vector();
Vector withdraw = new Vector();
Vector deposit = new Vector();
int i,choice=0,j=0,k=0,l;
float bal,no,amt;
Bank b[]=new Bank[1000];
Withdraw w[]=new Withdraw[1000];
Deposit d[]=new Deposit[1000];
System.out.println("Enter name, account number and balance of 3 account holders:");
for(i=0;i<=2;i++)
{
b[i]=new Bank();
str1=br.readLine();
str=br.readLine();
no=Float.parseFloat(str);
str=br.readLine();
bal=Float.parseFloat(str);
b[i].accept(str1,no,bal);
bank.addElement(b[i]);
}
while(choice!=5)
{
System.out.println("1.Add new customer\n2.Withdrawal \n3.Deposit\n4. View Contents\n5. Exit\nEnter your choice:");
str=br.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1: System.out.println("Enter name, account number and balance:");
str1=br.readLine();
str=br.readLine();
no=Float.parseFloat(str);
str=br.readLine();
bal=Float.parseFloat(str);
b[i]=new Bank();
b[i].accept(str1,no,bal);
bank.addElement(b[i]);
i++;
break;
case 2: System.out.println("Enter account number, amount and date:");
str=br.readLine();
no=Float.parseFloat(str);
str=br.readLine();
amt=Float.parseFloat(str);
str1=br.readLine();
w[j]=new Withdraw();
w[j].accept(str1,no,amt);
withdraw.addElement(w[j]);
j++;
l=0;
while(b[l].acc_no!=no)
{
l++;
}
bank.removeElement(b[l]);
b[l].balance-=amt;
bank.addElement(b[l]);
break;
case 3: System.out.println("Enter account number, amount and date:");
str=br.readLine();
no=Float.parseFloat(str);
str=br.readLine();
amt=Float.parseFloat(str);
str1=br.readLine();
d[k]=new Deposit();
d[k].accept(str1,no,amt);
deposit.addElement(d[k]);
k++;
l=0;
while(b[l].acc_no!=no)
{
l++;
}
bank.removeElement(b[l]);
b[l].balance+=amt;
bank.addElement(b[l]);
break;
case 4: for(i=0;i<=bank.size()-1;i++)
{
System.out.println(bank.elementAt(i));
}
break;
case 5: break;
default: System.out.println("Invalid choice");
}
}
}
}
--------------------------------------------
75) Data Sum..
--------------------------------------------
import java.io.*;
class Data{
protected int a, b;
public void read(int x, int y)
{
a=x;
b=y;
}
}
class Sum extends Data
{
private int sum;
public void add()
{
sum=a+b;
}
public void display()
{
System.out.println("Sum="+sum);
}
}
class Main{
public static void main (String args[]) throws IOException{
int x,y;
String str;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter two numbers");
str=br.readLine();
x=Integer.parseInt(str);
str=br.readLine();
y=Integer.parseInt(str);
Sum s=new Sum();
s.read(x,y);
s.add();
s.display();
}
}
--------------------------------------------
76) Area-Data
--------------------------------------------
import java.io.*;
class Data{
protected float r;
public void read(float x)
{
r=x;
}
}
class Area extends Data
{
private float area;
public void calculate()
{
area=3.14f*r*r;
}
public void display()
{
System.out.println("Area="+area);
}
}
class Main{
public static void main (String args[]) throws IOException{
float x;
String str;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter the radius:");
str=br.readLine();
x=Float.parseFloat(str);
Area a=new Area();
a.read(x);
a.calculate();
a.display();
}
}
--------------------------------------------
77) Area, Volume
--------------------------------------------
import java.io.*;
class Data{
protected float r;
public void read(float x)
{
r=x;
}
}
class Area extends Data
{
protected float area;
public void calculate()
{
area=3.14f*r*r;
}
public void display()
{
System.out.println("Area="+area);
}
}
class Volume extends Area{
private float volume;
public void compute()
{
volume=area*r*4/3;
}
public void output()
{
System.out.println("Volume="+volume);
}
}
class Main{
public static void main (String args[]) throws IOException{
float x;
String str;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter the radius:");
str=br.readLine();
x=Float.parseFloat(str);
Volume a=new Volume();
a.read(x);
a.calculate();
a.display();
a.compute();
a.output();
}
}
--------------------------------------------
78) Person Account
--------------------------------------------
import java.io.*;
class Person{
protected int code;
String name;
}
class Account extends Person
{
protected float pay;
}
class Admin extends Account{
private int exp;
public void accept(String s, int c, float p, int e)
{
name=s;
code=c;
pay=p;
exp=e;
}
public void display()
{
System.out.println("Name:"+name+"\nCode:"+code+"\nPay:"+pay+"\nExp:"+exp);
}
}
class Main{
public static void main (String args[]) throws IOException{
float pay;
int c,e;
String str,str1;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter name, code, pay and exp:");
str1=br.readLine();
str=br.readLine();
c=Integer.parseInt(str);
str=br.readLine();
pay=Float.parseFloat(str);
str=br.readLine();
e=Integer.parseInt(str);
Admin a=new Admin();
a.accept(str1,c,pay,e);
a.display();
}
}
--------------------------------------------
79) Staff, Officer, Typist, Casual etc
--------------------------------------------
import java.io.*;
class Staff
{
protected String name;
protected int code;
}
class Teacher extends Staff
{
private String subject;
private int experience;
public void read() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, code, subject and experience of the teacher:");
name=br.readLine();
str=br.readLine();
code=Integer.parseInt(str);
subject=br.readLine();
str=br.readLine();
experience=Integer.parseInt(str);
}
public void display()
{
System.out.println("Teacher Details:\nName:"+name+"\nCode:"+code+"\nSubject:"+subject+"\nExperience:"+experience);
}
}
class Officer extends Staff
{
private String dept;
private int grade;
public void read()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, code, department and grade of the officer:");
name=br.readLine();
str=br.readLine();
code=Integer.parseInt(str);
dept=br.readLine();
str=br.readLine();
grade=Integer.parseInt(str);
}
public void display()
{
System.out.println("Officer Details:\nName:"+name+"\nCode:"+code+"\nDepartment:"+dept+"\nGrade:"+grade);
}
}
class Typist extends Staff
{
protected int speed,experience;
}
class Regular extends Typist
{
private float salary;
public void read()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, code, speed, experience and salary of the regular typist:");
name=br.readLine();
str=br.readLine();
code=Integer.parseInt(str);
str=br.readLine();
speed=Integer.parseInt(str);
str=br.readLine();
experience=Integer.parseInt(str);
str=br.readLine();
salary=Float.parseFloat(str);
}
public void display()
{
System.out.println("Regular Typist Details:\nName:"+name+"\nCode:"+code+"\nSpeed:"+speed+"\nExperience:"+experience+"\nSalary:"+salary);
}
}
class Casual extends Typist
{
private float dailywages;
public void read()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, code, speed, experience and dailywages of the Casual typist:");
name=br.readLine();
str=br.readLine();
code=Integer.parseInt(str);
str=br.readLine();
speed=Integer.parseInt(str);
str=br.readLine();
experience=Integer.parseInt(str);
str=br.readLine();
dailywages=Float.parseFloat(str);
}
public void display()
{
System.out.println("Casual Typist Details:\nName:"+name+"\nCode:"+code+"\nSpeed:"+speed+"\nExperience:"+experience+"\nDaily Wages:"+dailywages);
}
}
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int choice;
System.out.println("1. Teacher\n2. Officer\n3. Regular Typist\n4. Casual Typist\nEnter the choice, whose details you want to enter:");
str=br.readLine();
choice=Integer.parseInt(str);
switch(choice)
{
case 1:Teacher t=new Teacher();
t.read();
t.display();
break;
case 2:Officer o=new Officer();
o.read();
o.display();
break;
case 3:Regular r=new Regular();
r.read();
r.display();
break;
case 4:Casual c=new Casual();
c.read();
c.display();
break;
default:System.out.println("Invalid choice");
}
}
}
--------------------------------------------
80) Bank Account, Saving..etc
--------------------------------------------
import java.io.*;
class Bank
{
protected String name;
protected int acc_no;
protected String type;
protected boolean cheque;
protected float penalty;
protected float min_bal;
protected float balance;
protected float interest;
}
class Current_acc extends Bank
{
public void read() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, account number, penalty, minimum balance and opening balance of the current account holder:");
name=br.readLine();
str=br.readLine();
acc_no=Integer.parseInt(str);
str=br.readLine();
penalty=Integer.parseInt(str);
str=br.readLine();
min_bal=Integer.parseInt(str);
str=br.readLine();
balance=Integer.parseInt(str);
type="Current";
cheque=true;
interest=0;
}
public void deposit(float x)
{
balance+=x;
}
public void display()
{
System.out.println("Account Details:\nName:"+name+"\nAccount no:"+acc_no+"\nBalance:"+balance+"\nCheque book facility:"+cheque);
}
public void withdraw(float x)
{
balance-=x;
}
public void minimum()
{
if(balance<min_bal)
balance-=penalty;
System.out.println("Penalty imposed");
}
}
class Savings_acc extends Bank
{
public void read() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter name, account number, interest rate and opening balance of the current account holder:");
name=br.readLine();
str=br.readLine();
acc_no=Integer.parseInt(str);
penalty=0;
min_bal=0;
str=br.readLine();
interest=Float.parseFloat(str);
str=br.readLine();
balance=Integer.parseInt(str);
type="Savings";
cheque=false;
}
public void deposit(float x)
{
balance+=x;
}
public void display()
{
System.out.println("Account Details:\nName:"+name+"\nAccount no:"+acc_no+"\nBalance:"+balance+"\nCheque book facility:"+cheque);
}
public void withdraw(float x)
{
balance-=x;
}
public void interestAdd()
{
balance=balance+balance*interest;
System.out.println("Interest Added");
}
}
class Main
{
public static void main(String args[])throws IOException
{
Current_acc c=new Current_acc();
c.read();
c.deposit(10000);
c.withdraw(5000);
c.display();
Savings_acc s=new Savings_acc();
s.read();
s.deposit(10000);
s.withdraw(5000);
s.display();
}
}
--------------------------------------------
81) Base, Sphere , Hemisphere
--------------------------------------------
import java.io.*;
class Base{
protected float r,vol;
public void read(float x)
{
r=x;
}
final public void display()
{
System.out.println("Volume="+vol);
}
}
class Sphere extends Base
{
public void calculate()
{
vol=3.14f*r*r*r*4/3;
}
}
class Hemisphere extends Base
{
public void calculate()
{
vol=3.14f*r*r*r*2/3;
}
}
class Main{
public static void main (String args[]) throws IOException{
float x;
String str;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter the radius:");
str=br.readLine();
x=Float.parseFloat(str);
Sphere s=new Sphere();
s.read(x);
s.calculate();
System.out.println("Sphere:");
s.display();
Hemisphere h=new Hemisphere();
h.read(x);
h.calculate();
System.out.println("Hemisphere:");
h.display();
}
}
--------------------------------------------
82) Base , Rectangle, Triangle & Circle
--------------------------------------------
import java.io.*;
abstract class Base{
protected float r,l,b,area;
abstract void calculate();
public void display()
{
System.out.println("Area="+area);
}
}
class Circle extends Base
{
public void read(float x)
{
r=x;
}
public void calculate()
{
area=3.14f*r*r;
}
}
class Rectangle extends Base
{
public void read(float x, float y)
{
l=x;
b=y;
}
public void calculate()
{
area=l*b;
}
}
class Triangle extends Base
{
public void read(float x, float y)
{
l=x;
b=y;
}
public void calculate()
{
area=0.5f*l*b;
}
}
class Main{
public static void main (String args[]) throws IOException{
float x,y;
String str;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Circle:");
System.out.println("Enter the radius:");
str=br.readLine();
x=Float.parseFloat(str);
Circle s=new Circle();
s.read(x);
s.calculate();
s.display();
System.out.println("Rectangle:");
System.out.println("Enter length and breadth:");
str=br.readLine();
x=Float.parseFloat(str);
str=br.readLine();
y=Float.parseFloat(str);
Rectangle h=new Rectangle();
h.read(x,y);
h.calculate();
h.display();
System.out.println("Triangle:");
System.out.println("Enter height and breadth:");
str=br.readLine();
x=Float.parseFloat(str);
str=br.readLine();
y=Float.parseFloat(str);
Triangle t=new Triangle();
t.read(x,y);
t.calculate();
t.display();
}
}
--------------------------------------------
83) Parent , Child
--------------------------------------------
import java.io.*;
class Parent
{
public void display(int x)
{
System.out.println("x="+x);
}
}
class Child extends Parent
{
public void display(int x, int y)
{
System.out.println("x="+x+"\ny="+y);
}
}
class Main
{
public static void main(String args[])
{
Child c=new Child();
c.display(10);
c.display(5,5);
}
}
--------------------------------------------
84) Divide
--------------------------------------------
import java.io.*;
class Divide{
public static void main(String args[]) throws IOException{
int a,b,res;
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String str;
System.out.println("Enter two numbers:");
str=br.readLine();
a=Integer.parseInt(str);
str=br.readLine();
b=Integer.parseInt(str);
res=a/b;
System.out.println("The Quotient=" + res);
}
}
--------------------------------------------
85) Star Slash
--------------------------------------------
import java.io.*;
class Star extends Thread
{
public void run()
{
int i;
for(i=1;i<=7;i++)
{
System.out.print("*");
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class Slash extends Thread
{
public void run()
{
int i;
for(i=1;i<=7;i++)
{
System.out.print("/");
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class Main
{
public static void main(String args[])
{
Star n=new Star();
Thread t1=new Thread(n);
Slash n1=new Slash();
Thread t2=new Thread(n1);
t1.start();
t2.start();
}
}
--------------------------------------------
86) Alphabets, Numbers..
--------------------------------------------
import java.io.*;
class Alphabets extends Thread
{
public void run()
{
int i;
for(i=1;i<=26;i++)
{
System.out.println((char)(i+64));
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class Numbers extends Thread
{
public void run()
{
int i;
for(i=1;i<=10;i++)
{
System.out.println(i);
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class Main
{
public static void main(String args[])
{
Alphabets n=new Alphabets();
Thread t1=new Thread(n);
Numbers n1=new Numbers();
Thread t2=new Thread(n1);
t1.start();
t2.start();
}
}
--------------------------------------------
87) IsaliveJoin
--------------------------------------------
import java.io.*;
class A extends Thread
{
public void run()
{
int i;
for(i=1;i<=2;i++)
{
System.out.println("In class a");
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class B extends Thread
{
public void run()
{
int i;
for(i=1;i<=2;i++)
{
System.out.println("In class b");
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class C extends Thread
{
public void run()
{
int i;
for(i=1;i<=2;i++)
{
System.out.println("In class c");
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
}
class IsaliveJoin
{
public static void main(String args[])
{
A a=new A();
Thread t1=new Thread(a);
B b=new B();
Thread t2=new Thread(b);
C c=new C();
Thread t3=new Thread(c);
t1.start();
t2.start();
t3.start();
System.out.println("Thread t1 is alive:"+t1.isAlive());
System.out.println("Thread t2 is alive:"+t2.isAlive());
System.out.println("Thread t3 is alive:"+t3.isAlive());
try
{
t1.join();
t2.join();
t3.join();
}
catch(InterruptedException ie)
{
}
System.out.println("Thread t1 is alive:"+t1.isAlive());
System.out.println("Thread t2 is alive:"+t2.isAlive());
System.out.println("Thread t3 is alive:"+t3.isAlive());
}
}
--------------------------------------------
88) Date and Time
--------------------------------------------
import java.util.*;
class DateTime
{
public static void main(String args[])
{
Date d=new Date();
System.out.println(d);
}
}
--------------------------------------------
89) Luck
--------------------------------------------
import java.awt.*;
import java.applet.*;
public class Luck extends Applet {
public void paint(Graphics g) {
g.drawString("All the best", 10, 10);
}
}
--------------------------------------------
90) Luck 1
--------------------------------------------
import java.awt.*;
import java.applet.*;
public class Luck extends Applet {
public void paint(Graphics g) {
g.drawString("All the best", 10, 10);
}
}
--------------------------------------------
91) Applet Parameters
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Parameters.class width=200 height=150>
<param name=Name value="Ajay">
<param name=Age value=19>
</applet>
*/
public class Parameters extends Applet {
public void paint(Graphics g) {
String name;
int age;
name=getParameter("Name");
age=Integer.parseInt(getParameter("Age"));
g.drawString(name+" is "+age+" years old",10,10);
}
}
--------------------------------------------
92) Lines in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Lines.class width=200 height=150>
</applet>
*/
public class Lines extends Applet {
public void paint(Graphics g) {
g.drawLine(10,10,50,10);
g.drawLine(10,20,50,20);
g.drawLine(15,15,15,55);
g.drawLine(25,15,25,55);
}
}
--------------------------------------------
93) Rectangles in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Rectangles.class width=300 height=350>
</applet>
*/
public class Rectangles extends Applet {
public void paint(Graphics g) {
g.drawRect(10,10,50,10);
g.fillRect(60,70,50,20);
g.drawRoundRect(105,105,50,25,10,10);
g.fillRoundRect(205,215,50,50,10,10);
}
}
--------------------------------------------
94) Ovals in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Ovals.class width=300 height=350>
</applet>
*/
public class Ovals extends Applet {
public void paint(Graphics g) {
g.drawOval(10,10,50,10);
g.fillOval(60,70,50,50);
}
}
--------------------------------------------
95) Arcs in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Arcs.class width=200 height=150>
</applet>
*/
public class Arcs extends Applet {
public void paint(Graphics g) {
g.drawArc(10,10,50,100,180,180);
g.fillArc(60,70,50,50,90,90);
}
}
--------------------------------------------
96) Polygons in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Polygons.class width=200 height=150>
</applet>
*/
public class Polygons extends Applet {
public void paint(Graphics g) {
int i;
int x[]={25,5,5,45,45,25};
int y[]={25,45,65,65,45,25};
g.drawPolygon(x,y,6);
for(i=0;i<=5;i++)
{
x[i]+=50;
y[i]+=50;
}
g.fillPolygon(x,y,6);
}
}
import java.awt.*;
import java.applet.*;
/*
<applet code=Polygons.class width=200 height=150>
</applet>
*/
public class Polygons extends Applet {
public void paint(Graphics g) {
Color red=new Color(255,0,0);
Color green=new Color(0,255,0);
Color blue=new Color(0,0,255);
Color yellow=new Color(255,255,0);
g.setColor(red);
g.drawLine(10,10,40,40);
g.setColor(green);
g.drawRect(10,60,20,20);
g.setColor(blue);
g.drawOval(80,10,40,40);
g.setColor(yellow);
g.fillArc(80,80,40,40,90,270);
}
}
--------------------------------------------
97) Font in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Font.class width=200 height=600>
</applet>
*/
public class Font extends Applet {
public void paint(Graphics g) {
GraphicsEnvironment e=GraphicsEnvironment.getLocalGraphicsEnvironment();
int i;
String Fonts[];
Fonts=e.getAvailableFontFamilyNames();
for(i=0;i<=Fonts.length-1 && i<=40;i++)
g.drawString(Fonts[i],1,15*i);
}
}
--------------------------------------------
98) Smiley in Applets
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Smiley.class width=200 height=150>
</applet>
*/
public class Smiley extends Applet {
public void paint(Graphics g) {
g.drawOval(10,10,40,15);
g.drawOval(90,10,40,15);
g.drawLine(70,20,70,50);
g.drawLine(40,60,100,60);
}
}
--------------------------------------------
99) Smiley
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Smiley.class width=200 height=150>
</applet>
*/
public class Smiley extends Applet {
public void paint(Graphics g) {
g.drawOval(10,10,40,15);
g.drawOval(90,10,40,15);
g.drawLine(70,20,70,50);
g.drawArc(40,50,50,20,180,180);
}
}
--------------------------------------------
100) Graphics in Applets-Hello
--------------------------------------------
import java.awt.*;
import java.applet.*;
/*
<applet code=Hello.class width=200 height=150>
</applet>
*/
public class Hello extends Applet {
public void paint(Graphics g) {
g.drawString("Hello java", 10, 10);
}
}
No comments:
Post a Comment