IBM | TATA STEEL | AMAZON OA CODING SOLUTIONS
Kanalga Telegram’da o‘tish
We provide help for all Exam... Anyone can contact me @AK_Coder for Exam clearance and interviews Trusted ✅
Ko'proq ko'rsatish2 100
Obunachilar
Ma'lumot yo'q24 soatlar
-87 kun
-2130 kun
Postlar arxiv
🚨TCS PRA ITIS MARCH 30th FAILED CANDIDATES
Can book your slot now..
Who want to clear ping me @ThorH5
import java.util.*;
public class Solution{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
FruitStore[] model=new FruitStore[n];
for(int i=0;i<n;i++) {
model[i]=new FruitStore(sc.nextInt(), sc.nextLine()+sc.nextLine(), sc.nextLine(), sc.nextInt());
}
int arg= sc.nextInt();
if(getFruitByItemNo(model,arg)==null)
System.out.println("No fruits found");
else
System.out.println(getFruitByItemNo(model,arg));
if(getFruitOfMaxPrice(model)==null)
System.out.println("No fruits found");
else {
System.out.println(getFruitOfMaxPrice(model));
}
}
//1st
public static FruitStore getFruitByItemNo(FruitStore[] arr, int itemNo){
FruitStore res=null;
for(FruitStore f:arr) {
if(f.getItemNo()==itemNo)
res=f;
}
return res;
}//end 1st
//2nd
public static FruitStore getFruitOfMaxPrice(FruitStore[] arr){
FruitStore[] res=Arrays.asList(arr).stream().sorted((s1,s2)->{
return s2.getPrice()-s1.getPrice();
}).toArray(size-> new FruitStore[size]);
if(res.length==0)
return null;
return res[0];
}//end 2nd
}//end solution class
class FruitStore{
private int itemNo;
private String name;
private String color;
private int price;
public FruitStore() {
}
public FruitStore(int itemNo, String name, String color, int price) {
super();
this.itemNo = itemNo;
this.name = name;
this.color = color;
this.price = price;
}
public int getItemNo() {
return itemNo;
}
public void setItemNo(int itemNo) {
this.itemNo = itemNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String toString() {
return itemNo + "\n" + name + "\n" + color + "\n" + price ;
}
}
✅FruitStore code
Java
Python
Telegram: @tcs_pra_ira_help
