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
} 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
{ if(a.charAt(i)
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
res[j]) { temp=res[i]; res[i]=res[j]; res[j]=temp; } } } for(i=0;i
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
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;is2[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; } }