top of page
Home: Blog2
Writer's pictureAnuj Yadav

UNIX AND JAVA SOLUTION 08-05-2020

Total time for this section was 70 minutes and there were two questions.



UNIX SOLUTION

There was only one question.

We have to basically find the difference of the sum of the square of even and odd numbers.





read N
i=1
sum=0
even=0
odd=0
while [ $i -le $N ]
do
  read num         
  if [ $((num%2)) -eq 0 ]
  then
    even=$((even+num*num))
  else
    odd=$((odd+num*num))
  fi
  i=$((i + 1))
done
sum=$((even-odd))
echo $sum



JAVA SOLUTION


There was an OOPs based question.







Note: My solution is violating the OOPs principle but our aim was only to pass the test cases. Using getters and setters is highly recommended.

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)
    {
        Scanner sc= new Scanner(System.in);
        int temp=0,k;
        String s="",l="";
        Player o1=new Player();
        Player o2=new Player();
        Player o3=new Player();
        Player o4=new Player();
        Player p[]={o1,o2,o3,o4};
        for (int i=0;i<p.length;i++)
        {
            p[i].pid=sc.nextInt();
            sc.nextLine();
            p[i].skill=sc.next();
            p[i].level=sc.next();
            p[i].points=sc.nextInt();
        }
     s=sc.next().toUpperCase();
     l=sc.next().toUpperCase();
    for (k=0;k<p.length;k++)
    {
        if (p[k].skill.toUpperCase().equals(s))
        {
            temp=temp+p[k].points;
        }
    }
    if (temp>0)
    {
        System.out.println(temp);
    }
    else
    {
        System.out.println("The given Skill is not available");
    }
    int id=0;
    for (int j=0;j<p.length;j++)
    {
        if (p[j].level.toUpperCase().equals(l) && p[j].points>=20)
        {
            id=p[j].pid;
            break;
        }
    }
    if (id!=0)
    {
        System.out.println(id);
    }
    else
    {
        System.out.println("No player is available with specified level, skill and eligibility points");
    }

}
}   
class Player
{
     int pid;
     String skill;
     String level;
     int points;
}   
   

97 views0 comments

Recent Posts

See All

Comments


Home: Subscribe

CONTACT

 Kanpur, India

8299229032

  • twitter

Thanks for submitting!

Home: Contact
bottom of page