STUDENT WITH SAME AGE & CITY

public class Student{
      public String name,city;
      public double age;
      public Student(String name,double age,String city){
      this.name=name;
      this.age=age;
      this.city=city;

      }
}


 



------------------------------------------------------------------------------------------------------------------------------------------------------
 


 


  


Solution.java


------------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Solution{
    public static int studentCountWithSameCityAndAge(Student s1,Student             s2,Student s3){
        int count=0;
        if((s1.city.equals(s2.city))&&(s1.age==s2.age)){
            count=2;
        if((s1.age==s3.age)&&(s1.city.equals(s3.city)))
            count++;
        }
        else if((s3.city.equals(s1.city))&&(s1.age==s3.age)){
            count=2;
        } 
        else if((s3.city.equals(s2.city))&&(s3.age==s2.age)){
            count=2;
        }
    return count;
    }
public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String name,city;
    int age;
    name=sc.nextLine();
    age=sc.nextInt();
    sc.nextLine();
    city=sc.nextLine();
    Student s1=new Student(name,age,city);
    name=sc.nextLine();
    age=sc.nextInt();
    sc.nextLine();
    city=sc.nextLine();
    Student s2=new Student(name,age,city);
    name=sc.nextLine();
    age=sc.nextInt();
    sc.nextLine();
    city=sc.nextLine();
    Student s3=new Student(name,age,city);
    System.out.println(Solution.studentCountWithSameCityAndAge(s1,s2,s3));



    }
}


Comments

  1. Can u give for python bbr ...?

    ReplyDelete
  2. Tioga Classic Stainless Steel - Tioga-Arts
    Tioga Classic Stainless ti89 titanium calculator Steel | Tioga-Arts. $28.00. Tioga Classic Stainless Steel. Made with ti89 titanium calculators the titanium bong highest quality components, these titan metal stainless steel $27.00 · ‎Out of is titanium expensive stock

    ReplyDelete

Post a Comment

Popular Posts