0% found this document useful (0 votes)
2K views

Tcs Java Programs

The document contains Java code defining classes for Employees, Documents, Students and Points. It includes methods to find the employee with the maximum age, summarize document details, retrieve students by city and marks, calculate distance between points and check if a number is prime or its reverse is prime. The code takes input, performs various operations on the objects and prints output.

Uploaded by

bhavana T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Tcs Java Programs

The document contains Java code defining classes for Employees, Documents, Students and Points. It includes methods to find the employee with the maximum age, summarize document details, retrieve students by city and marks, calculate distance between points and check if a number is prime or its reverse is prime. The code takes input, performs various operations on the objects and prints output.

Uploaded by

bhavana T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

public class Main

public static void main(String[] args) {

Employee a1=new Employee(1,"aaa",22);

Employee a2=new Employee(2,"bbb",44);

Employee a3=new Employee(3,"ccc",55);

maxage(a1,a2,a3);

public static void maxage(Employee a1,Employee a2, Employee a3)

if((a1.getage()>a2.getage())&&(a1.getage()>a3.getage()))

System.out.println(a1.getid()+" "+a1.getname()+" "+a1.getage());

else if((a2.getage()>a1.getage())&&(a2.getage()>a3.getage()))

System.out.println(a2.getid()+" "+a2.getname()+" "+a2.getage());

else

System.out.println(a3.getid()+" "+a3.getname()+" "+a3.getage());

}
public class Employee

int id,age;

String name;

public Employee(int id,String name,int age)

this.id=id;

this.name=name;

this.age=age;

public int getid()

return id;

public String getname()

return name;

public int getage()

return age;

public void setid(int id)

{
this.id=id;

public void setname(String name)

this.name=name;

public void setage(int age)

this.age=age;

public class Employee

int age;

String name,city;

public Employee(String name,int age,String city)

this.city=city;

this.name=name;

this.age=age;

public String getcity()

{
return city;

public String getname()

return name;

public int getage()

return age;

public class Main

public static void main(String[] args) {

Employee a1=new Employee("aaa",22,"pune");

Employee a2=new Employee("bbb",22,"pune");

Employee a3=new Employee("ccc",22,"pune");

System.out.println(maxage(a1,a2,a3));

public static int maxage(Employee a1,Employee a2, Employee a3)

int c;

if((a1.getage()==a2.getage())&&(a1.getcity().equals(a2.getcity())))

c=2;
if((a1.getage()==a3.getage())&&(a1.getcity().equals(a3.getcity())))

c=3;

else

c=2;

else if((a2.getage()==a3.getage())&&(a2.getcity().equals(a3.getcity())))

c=2;

else

c=0;

return c;

public class Main{

public static void main(String args[])

Employee e1=new Employee(1,"aaa",22);

Employee e2=new Employee(2,"bbb",11);


Employee e3=new Employee(3,"ccc",55);

Employee e4=new Employee(4,"ddd",44);

Employee e[]=new Employee[]{e1,e2,e3,e4};

int i,j;

double t;

for(i=0;i<4;i++)

for(j=i+1;j<4;j++)

if(e[i].age>e[j].age)

t=e[i].age;

e[i].age=e[j].age;

e[j].age=t;

System.out.println(e[1].age)

public class Employee{

int id;

String name;

double age;
public Employee(int id,String name,double age){

this.id=id;

this.name=name;

this.age=age;

import java.util.*;

public class Main

public static void main (String[] args)

int arr[]=new int[]{111,77,88,44,32,11,13,25,44};

Arrays.sort(arr);

for(int i=0;i<arr.length;i++)

if(arr[i]%2!=0)

System.out.print(arr[i]+" ");

import java.util.*;
public class Main

public static void main (String[] args)

int arr[]=new int[]{111,77,88,44,32,11,13,25,44};

int i=1,t;

while(i<arr.length-1)

if(arr[i]<arr[i-1])

t=arr[i];

arr[i]=arr[i-1];

arr[i-1]=t;

i+=2;

System.out.println(Arrays.toString(arr));

public class Main{

public static void main(String args[])

Point p1=new Point(-3,-4);

Point p2=new Point(0,0);


Point p3=new Point(4,3);

Point p4=new Point(16,-3);

Point p[]=new Point[]{p1,p2,p3,p4};

shortdis(p);

public static void shortdis(Point p[])

{int i;

double x1,y1,l=0;

for(i=1;i<p.length;i++){

x1=p[i].getX()-p[i-1].getX();

y1=p[i].getY()-p[i-1].getY();

l=l+Math.sqrt((x1*x1)+(y1*y1));

System.out.println(l);

public class Point{

double x;

double y;

public Point(double x,double y)

this.x=x;

this.y=y;
}

public double getX()

return x;

public double getY()

return y;

Smallest ascii character

import java.util.*;

public class Main{

public static void main(String args[])

String str="GeEksforGeeks";

int size=str.length();

System.out.println(smallest(str,size));

public static char smallest(String a, int n)

char c='z';

for(int i=0;i<n-1;i++)
{

if(a.charAt(i)<c)

c=a.charAt(i);

return c;

import java.util.*;
public class Solution{
public static Document output(Document[] doc)
{
int j=doc[0].getid();
int page=0;
for(int i=1;i<4;i++)
{
if(j<doc[i].getid()){j=doc[i].getid();}
}
String
t=doc[0].gettitle()+"#"+doc[1].gettitle()+"#"+doc[2].gettitle()+"#"+doc[3].gettitle();
String
f=doc[0].getfolder()+"@"+doc[1].getfolder()+"@"+doc[2].getfolder()+"@"+doc[3].getfolde
r();
page=doc[0].getpage()+doc[1].getpage()+doc[2].getpage()+doc[3].getpage();
Document out=new Document(j+1,t,f,page);

return out;
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
Document doc[]=new Document[4];
for(int i=0;i<4;i++)
{
int id=sc.nextInt();sc.nextLine()
String title=sc.nextLine();
System.out.println("enter folder");
String folder=sc.nextLine();
System.out.println("enter pages");
int pages=sc.nextInt();
doc[i]=new Document(id,title,folder,pages);
}
Document result=output(doc);
System.out.println(result.getid());
System.out.println(result.gettitle());
System.out.println(result.getfolder());
System.out.println(result.getpage());
}
}
------------------------
document.java
import java.util.*;
public class Document{
int id;
String title,folder;
int pages;
public Document(int id, String title,String folder,int pages)
{
this.id=id;
this.title=title;
this.folder=folder;
this.pages=pages;
}
public int getid(){return id;}
public String gettitle(){return title;}
public String getfolder(){return folder;}
public int getpage(){return pages;}
public void setid(int id){this.id=id;}
public void settitle(String title){this.title=title;}
public void setfolder(String folder){this.folder=folder;}
public void setpage(int pages){this.pages=pages;}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {


public static void main(String args[] ) throws Exception {
int n,i,j,ind=0,flag,temp;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int arr[] = new int[n];
int res[] = new int[n];
for(i=0;i<n;i++)
{
flag=0;
arr[i] = sc.nextInt();
flag += checkPrime(arr[i]);
temp = revNum(arr[i]);
flag += checkPrime(temp);
if(flag==2)
res[ind++]=arr[i];
}
for(i=0;i<ind-1;i++)
{
for(j=i+1;j<ind;j++)
{
if(res[i]>res[j])
{
temp=res[i];
res[i]=res[j];
res[j]=temp;
}
}
}
for(i=0;i<ind;i++)
System.out.println(res[i]);
}

public static int checkPrime(int n)


{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
return 1;
else
return 0;
}
public static int revNum(int n)
{
int s=0,r;
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
return s;
}
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {


static int len=0;
public static void main(String args[] ) throws Exception {
int n,i,id;
String name,city;
double marks;
Scanner sc=new Scanner(System.in);
n = sc.nextInt();
Student s[] = new Student[n];
Student s1[] = new Student[n];
for(i=0;i<n;i++)
{
id = sc.nextInt();sc.nextLine();
name = sc.nextLine();
city = sc.nextLine();
marks = sc.nextDouble();sc.nextLine();
s[i] = new Student(id,name,city,marks);
}
city = sc.nextLine();
marks = sc.nextDouble();
s1 = getStudentsWithCityAndMarks(s, city, marks);
System.out.println(len);
for(i=0;i<len;i++)
System.out.println(s1[i].id+" "+s1[i].name+" "+s1[i].city+" "+s1[i].marks);
}

public static Student[] getStudentsWithCityAndMarks(Student[] students, String city,


double marks)
{
Student s2[] = new Student[students.length];
int i,j;
Student temp;
for(i=0;i<students.length;i++)
{
if(students[i].city.equals(city) && students[i].marks==marks)
s2[len++]=students[i];
}
for(i=0;i<len-1;i++)
{
for(j=i+1;j<len;j++)
{
if(s2[i].id>s2[j].id)
{
temp = s2[i];
s2[i]=s2[j];
s2[j]=temp;
}
}
}
return s2;
}
}

class Student
{
int id;
String name,city;
double marks;
Student(int id,String name,String city,double marks)
{
this.id=id;
this.name=name;
this.city=city;
this.marks=marks;
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy