Escolar Documentos
Profissional Documentos
Cultura Documentos
import java.io.*;
class Student
int rollno;
String name;
String depart;
Student(){}
rollno=r;
name=n;
depart=d;
Student(Student h)
rollno=h.rollno;
name=h.name;
depart=h.depart;
rollno=Integer.parseInt(br.readLine());
System.out.println("Enter the name of the Student:");
name=br.readLine();
depart=br.readLine();
void display()
System.out.println(rollno+"\t"+name+"\t"+depart);
x.read();
x.display();
y.display();
z.display();
/*2.*/
import java.util.*;
class Date
int d;
int m;
int y;
Date(){}
this.d=d;
this.m=m;
this.y=y;
return d+"/"+m+"/"+y;
class Point
int x;
int y;
Point(){}
Point(int x, int y)
{
this.x=x;
this.y=y;
return "("+x+","+y+")";
v.add(new Date(1,1,2001));
v.add(new Point(1,1));
v.add(new Integer(2));
v.add(new Double(2.3));
v.add("Hi");
Object o;
o=v.get(i);
System.out.println(o);
}
}
/*3.*/
class Volume
return Math.PI*r*r*h;
double findVolume(double r)
return 4/3*Math.PI*r*r*r;
double cylinder=v.findVolume(2.5,3.5);
double sphere=v.findVolume(4.5);
System.out.println(cylinder);
System.out.println(sphere);
}
/*4.*/
return Math.PI*r*r;
return (l*b);
double circle=getArea(1.0);
double rectangle=getArea(1,4);
System.out.println(circle);
System.out.println(rectangle);
/*5*/
class Main
{
public static void main(String[] args)
int a=0,b=-1,i=2,x=3,s,j[]={10,20};
String m="hi";
try{
int y=x/a;
catch(ArithmeticException e)
System.out.println(e);
try{
int p=j[b];
catch(NegativeArraySizeException e)
System.out.println(e);
try{
System.out.println(j[3]);
catch(ArrayIndexOutOfBoundsException e)
{System.out.println(e);}
try{
s=Integer.parseInt(m);
catch(NumberFormatException e)
{System.out.println(e);}
/*6*/
String s="";
LessNumberOfArguments(){}
LessNumberOfArguments(String x)
s=x;
int x=0;
try
x=fun(args.length);
System.out.println(x);
catch(LessNumberOfArguments e)
System.out.println(e);
if(a==0)
throw b;
return a;
/*7*/
class Complex
{
int r;
int i;
Complex(){}
Complex(int r, int i)
this.r=r;
this.i=i;
Complex add(Complex h)
d.r=r+h.r;
d.i=i+h.i;
return d;
return r+"+"+"i"+i;
{
Complex a=new Complex(1,2);
Complex d;
d=a.add(b);
/*9*/
import java.io.*;
class Book
{
String title;
double price;
Book()
{
price = 0;
}
Book(String t, double p)
{
title = t;
price = p;
}
boolean compare(double x)
{
boolean b = true;
if(price < x)
b = false;
return b;
}
void disp()
{
System.out.print("Title: "+title);
System.out.print("\nPrice: "+price);
}
}
class fred
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Book r1 = new Book("Lie to me",1000);
Book r2 = new Book("Two Men in a Boat",800);
if(r1.compare(r2.price))
{
System.out.println("The Costlier Book is:");
r1.disp();
}
else
{
System.out.println("The Costlier Book is:");
r2.disp();
}
}
}
/*10*/
import java.io.*;
class Nos
{
int n,temp1,temp2;
//Check condition
void check()
{
for(int n=1000;n<=9999;n++)
{
/*The no will be a perfect square if its square root is an integer*/
double a=Math.sqrt(n);
int b=(int)a;
if(a==b)
{
temp1=n%100;
temp2=n-temp1;
temp2=temp2/100;
double a2=Math.sqrt(temp2);
int b2=(int)a2;
if(b2==a2)
{
double a1=Math.sqrt(temp1);
int b1=(int)a1;
if(a1==b1)
{
System.out.println(n);
}
}
}
else
continue;
}
}
}
class PerfectSquare
{
public static void main(String args[])throws IOException
{
Nos n=new Nos();
n.check();
}
}
/*11*/
class Reverse
for(int i=10000;i<25000;i++)
int x=i*4;
int newno=0;
while(x!=0)
int digit=x%10;
newno=newno*10+digit;
x=x/10;
if(newno==i)
System.out.println(i+"\t");
/*12*/
import java.io.*;
class Symmatrix
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
boolean flag=true;
for(int i=0;i<3;i++)
a[i][j]=Integer.parseInt(br.readLine());
one:for(int i=0;i<a.length;i++)
if(a[i][j]!=a[j][i])
flag=false;
break one;
if(flag)
System.out.println("Symmetric");
}
else
System.out.println("not Symmetric");
/*13*/
class Prime
if(i%j==0)
continue one;
System.out.println(i);
/*14*/
class Date2
{
int d;
int m;
int y;
Date2(){}
this.d=d;
this.m=m;
this.y=y;
boolean compare(Date2 h)
return true;
else
return false;
return d+":"+m+":"+y;
{
public static void main(String args[])
boolean x=a.compare(b);
if(x)
else
/*15*/
class Time
int h;
int m;
Time(){}
Time(int h, int m)
this.h=h;
this.m=m;
Time add(Time q)
{
int a=m+q.m;
if(a>60)
x.m=a-60;
x.h=h+q.h+1;
else
x.m=a;
x.h=h+q.h;
return x;
return h+":"+m+"\t";
Time c=a.add(b);
import java.io.*;
class Matrix
int r;
int c;
int [][]a;
Matrix()
r=3;c=3;
a=new int[r][c];
Matrix(int r, int c)
this.r=r;
this.c=c;
a=new int[r][c];
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
a[i][j]=Integer.parseInt(br.readLine());
Matrix add(Matrix h)
x.a[i][j]=a[i][j]+h.a[i][j];
return x;
}
else
return null;
Matrix sub(Matrix h)
x.a[i][j]=a[i][j]-h.a[i][j];
return x;
else
return null;
Matrix transpose()
{
Matrix x=new Matrix(r,c);
x.a[i][j]=a[j][i];
return x;
Matrix multi(Matrix h)
x.a[i][j]=a[i][k]*h.a[k][j];
}
}
return x;
void display()
System.out.print(a[i][j]+"\t");
System.out.println();
a.set();
b.set();
Matrix p=a.add(b);
Matrix q=a.sub(b);
Matrix r=a.multi(b);
Matrix s=a.transpose();
p.display();
q.display();
r.display();
s.display();
// 20
import java.io.*;
class Employee
{
private String empname;
private int empno;
Employee()
{
empno = 0;
}
Employee(Employee x)
{
empname = x.empname;
empno = x.empno;
}
void update(Employee x)
{
empname = x.empname;
empno = x.empno;
}
String getname()
{
return empname;
}
void disp()
{
System.out.println(empno+"\t"+empname);
}
class SortEmployee
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Employee e[] = new Employee[5];
System.out.println("\nEnter Details of the Employees:");
for(int i = 0; i < 5; i++)
{
System.out.println("Employee "+(i+1));
System.out.print("\nName : ");
String n = br.readLine();
System.out.print("\nNumber : ");
int num = Integer.parseInt(br.readLine());
e[i] = new Employee(n, num);
}
int j = 0;
for(int i = 1; i < 5; i++)
{
for(j = 0; j < 5-i; j++)
{
String n1 = e[j].getname();
String n2 = e[j+1].getname();
if(n1.compareTo(n2) > 0)
{
Employee temp = new Employee(e[j]);
e[j].update(e[j+1]);
e[j+1].update(temp);
}
}
}
/*22. */
import java.io.*;
class occur
{
String s[]=new String[50];
String s2,s3;
int size;
int count=0;
void read_info()throws IOException
{
System.out.print("Enter the string: ");
DataInputStream d1=new DataInputStream(System.in);
s2=d1.readLine();
System.out.print("Enter the no. of words: ");
DataInputStream d=new DataInputStream(System.in);
size=Integer.parseInt(d.readLine());
for(int i=0;i<size;i++)
{
System.out.print("Enter the "+(i+1)+"th word: ");
DataInputStream d2=new DataInputStream(System.in);
s[i]=d2.readLine();
}
System.out.println("Enter the word whose occurence is to be checked");
DataInputStream d3=new DataInputStream(System.in);
s3=d3.readLine();
}
void check()
{
for(int i=0;i<size;i++)
{
if(s3.equalsIgnoreCase(s[i]))
count++;
}
System.out.println("The occurence of the word "+s3+" is "+count);
}
}
class Occurence
{
public static void main(String args[])throws IOException
{
occur o=new occur();
o.read_info();
o.check();
}
}
/*24*/
import java.io.*;
class Palindromee
{
public static void main(String args[])throws IOException
{
String s=new String();
DataInputStream d=new DataInputStream(System.in);
System.out.println("ENTER ANY STRING: ");
s=d.readLine();
String temp=s.toUpperCase();
char t[]=temp.toCharArray();
int l=temp.length();
boolean flag=true;
for(int i=0;i<l/2;i++)
{
if(t[i]!=t[l-1-i])
{
flag=false;
break;
}
}
if(flag==true)
System.out.println("ENTERED STRING \""+s+"\" IS PALINDROME");
else
System.out.println("ENTERED STRING \""+s+"\" IS NOT PALINDROME");
}
}
/* 25*/
import java.io.*;
class Main {
System.out.println("enter string");
char c[]=s.toCharArray();
for(int i=0;i<c.length/2;i++)
char temp=c[i];
c[i]=c[c.length-i-1];
c[c.length-i-1]=temp;
if(s.compareTo(bs)==0)
System.out.print("its palindrome");
else
System.out.print("not palindrome");
//Program 26
package college;
import java.io.*;
import java.util.*;
class Employee
{
private String name,designation;
private double salary;
static int COUNT=0;
static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
public void finalize() //over-riding the finalize() inheritted from the Object class
{
COUNT++;
}
}
class CountDemo
{
public static void main(String arg[]) throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Vector v=new Vector();
char c;
do
{
v.addElement(new Employee());
System.out.println("Do you want to create more Employees (Y/N) : ");
c=in.readLine().charAt(0);
} while(c=='y'||c=='Y');
System.out.println("The Number of Employees Created is "+Employee.COUNT);
}
/*29*/
import java.io.*;
class Student
{ String name;
int rolNo;
int m1,m2,m3;
void read()throws IOException
{ DataInputStream r= new DataInputStream(System.in);
System.out.println("enter name:");
name=r.readLine();
System.out.println("enter rollno:");
rolNo=Integer.parseInt(r.readLine());
System.out.println("enter marks of sub 1:");
m1=Integer.parseInt(r.readLine());
System.out.println("enter marks of sub 2:");
m2=Integer.parseInt(r.readLine());
System.out.println("enter marks of sub 3:");
m3=Integer.parseInt(r.readLine());
}
double avg()
{ return( m1+m2+m3)/3.0;
}
void display()
{ System.out.println("name of the student:"+name);
System.out.println("roll no is:"+rolNo);
System.out.println("average marks are:"+avg());
}
}
public class abc
{ public static void main(String[] args)throws IOException
{ Student s[]=new Student[3];
for(int i=0; i<3;i++)
{s[i] = new Student();
s[i].read();// error is comin here...
}
for(int i=1;i<2;i++)
for(int j=0;j<3-i;j++)
if(s[j].avg()<s[j+1].avg())
{ Student temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
for(int i=0;i<3; i++)
s[i].display();
}
}
/*31*/
class Rectangle
{protected int length, breadth;
public Rectangle(int length, int breadth)
{this.length = length; this.breadth= breadth;}
public int area()
{return length*breadth;}
}
class Box extends Rectangle
{int depth;
public Box(int l, int b, int d)
{super(l, b); depth = d; }
public double volume()
{return length*depth*breadth;}
}
class RectBox
{ public static void main(String[] args)
{Rectangle r = new Rectangle(10, 5);
System.out.println("Area of Rectangle is "+r.area());
Box b = new Box(4, 5, 6);
System.out.println("volume of box is "+b.volume());
}
}
/*32*/
import java.io.*;
abstract class Employee
{
int eno;
String ename;
Employee(int empNo,String empName)
{
eno = empNo;
ename = empName;
}
abstract double calSalary();
}
class SalariedEmployee extends Employee
{
double salary;
SalariedEmployee(int empNo, String empName,double sal)
{
super(empNo,empName);
salary = sal;
}
double calSalary()
{
return salary;
}
}
class HourlyEmployee extends Employee
{
double wages;
int days;
HourlyEmployee(int empNo,String empName,double wage, int day)
{
super(empNo,empName);
wages = wage;
days = day;
}
double calSalary()
{
return wages * days;
}
}
class CommissionEmployee extends Employee
{
double totalsale, per_rate,totSal;
CommissionEmployee(int empNo,String empName, double totSale, double per_Rat)
{
super(empNo,empName);
totalsale = totSale;
per_rate = per_Rat;
}
double calSalary()
{
return totalsale * per_rate;
}
}
class EmployeeImplement
{
public static void main(String args[])
{
SalariedEmployee SE = new SalariedEmployee(1,"Sachin",1200);
HourlyEmployee HE = new HourlyEmployee(2,"Sam",50,10);
CommissionEmployee CE = new CommissionEmployee(3,"Sammy",15,100);
Employee objEmp;
objEmp = SE;
System.out.println("Salary of Salaried Employee is "+objEmp.calSalary());
Employee objEmp1;
objEmp1 = HE;
System.out.println("Salary of Hourly Employee is "+objEmp1.calSalary());
Employee objEmp2;
objEmp2 = CE;
System.out.println("Salary of Commission Employee is "+objEmp2.calSalary());
}
}
/*34*/
import java.io.*;
interface TwoDShape
{
public void getArea();
public void getName();
}
Sphere(double a)
{r=a;
}
public void getArea()
{ System.out.println("area of circle is: "+3.14*r*r);
}