0% found this document useful (0 votes)
39 views

Pre Pra Java Solution

Solutions

Uploaded by

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

Pre Pra Java Solution

Solutions

Uploaded by

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

-----------------Pre PRA-------------

--------------Java-------------
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 {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Student[] students = new Student[n];
for (int i=0;i<n;i++)
{
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
int marks = sc.nextInt();
sc.nextLine();
int age = sc.nextInt();
sc.nextLine();
students[i] = new Student(id, name, marks, age);
}
int m = sc.nextInt();
Student s1 = findStudentWithMaximumAge(students);
if(s1==null)
{
System.out.println("No Student found with mentioned attribute.");
} else{
System.out.println("id-"+s1.getId());
System.out.println("name-"+s1.getName());
System.out.println("marks-"+s1.getMarks());
System.out.println("age-"+s1.getAge());
}
Student s2 = searchStudentById(students, m);
if(s2==null)
{
System.out.println("No Student found with mentioned attribute.");
} else{
System.out.println("id-"+s2.getId());
System.out.println("name-"+s2.getName());
System.out.println("marks-"+s2.getMarks());
System.out.println("age-"+s2.getAge());
}
}

public static Student findStudentWithMaximumAge(Student[] students)


{
int max = students[0].getAge();
Student s1=null;
for( int i=0; i<students.length; i++)
{
if (max<students[i].getAge())
{
max = students[i].getAge();
s1 = students[i];
}
}
return s1;
}

public static Student searchStudentById(Student[] students, int id)


{
for ( int i=0; i<students.length;i++)
{
if(id == students[i].getId())
{
return students[i];
}
}
return null;
}
}
class Student {
int id;
String name;
int marks;
int age;
public Student (int id, String name, int marks, int age)
{
this.id=id;
this.name=name;
this.marks=marks;
this.age=age;
}
public int getId(){return id;}
public String getName(){return name;}
public int getMarks(){return marks;}
public int getAge(){return age;}

---------------------Unix------------------------
awk 'BEGIN{FS="-";count=0;IGNORECASE=1;}
{
if($3>40)
{
print($1"-"$2"-"$3"-"$4);
count+=1;
}

}END{print("Total : " count)}'

You might also like