IBM HACKERRANK CODING SOLUTIONS
Открыть в Telegram
We provide help for all Exams... Anyone can contact me @AK_Coder for Exam clearance and interviews Trusted ✅
БольшеСтрана не указанаКатегория не указана
4 420
Подписчики
Нет данных24 часа
Нет данных7 дней
Нет данных30 дней
Архив постов
🔴Done with 2:30PM 25th march TCS off campus Exam
🤩🤩✨Premium group members all done with today exam
💯clearance done
We help limited slots n give 100% results🤩 al the time
✨✨✨✨✨✨✨✨✨✨✨✨✨
25 мар. 2022, 08:32
Does any one have tcs off campus written test
03 мар. 2022, 04:50
import java.util.*;
import java.lang.*;
public class Solution {
public static void main(String args[] ) throws Exception {
List<Toy>list=new ArrayList<>();
Scanner sc=new Scanner(System.in);
String num=sc.nextLine();
int n=Integer.parseInt(num);
for(int i=0;i<n;i++)
{
String id=sc.nextLine();
String name=sc.nextLine();
String quantity=sc.nextLine();
Toy toy=new Toy(Integer.parseInt(id),name,Double.parseDouble(quantity));
list.add(toy);
}
double avg=findAverageQuantityOfToy(list);
System.out.println("Average quantity:"+avg);
int id=sc.nextInt();
Toy toy=searchToyById(list, id);
if(toy!=null)
{
System.out.println("id-"+toy.getId());
System.out.println("name-"+toy.getName());
System.out.println("quantity-"+toy.getQuantity());
}
else
{
System.out.println("No Box found with the mentioned attribute");
}
}
//Method1
public static double findAverageQuantityOfToy(List<Toy>list)
{
double sum=0;
for(int i=0;i<list.size();i++)
{
sum+=list.get(i).getQuantity();
}
return sum/4;
}
//Method2
public static Toy searchToyById(List<Toy>list,int id)
{
Toy toy=null;
for(int i=0;i<list.size();i++)
{
if(list.get(i).getId()==id)
toy= list.get(i);
}
return toy;
}
}
class Toy
{
private int id;
private String name;
private double quantity;
public Toy(int id,String name,double quantity)
{
this.id=id;
this.name=name;
this.quantity=quantity;
}
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return id;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setQuantity(double quantity)
{
this.quantity=quantity;
}
public double getQuantity()
{
return quantity;
}
}
Java code 🔴
12 апр. 2022, 00:33
