Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  problem.java
Language: JAVA
Code:
import java.util.Scanner;
public class Problem {
    public static void main(String arg[]){
        Scanner ob=new Scanner(System.in);
        int time1, time2;
        System.out.println("How many rooms are there in musium: ");
        int room_count=ob.nextInt();
        if(room_count > 0){
            System.out.println("User 1 starts from room 1 \nUser 2 starts from room "+ room_count);
            if(room_count == 1){
                System.out.println("User 1 and User 2 meets in room no: " + room_count);
            }
            else{
                System.out.println("How much time(in sec) will spend in each room by the User1: ");  
                time1=ob.nextInt();
                System.out.println("How much time(in sec) will spend in each room by the User2: ");  
                time2=ob.nextInt();
                int result = ((room_count*time1*time2)/(time1+time2))/time1;
                if(room_count % 2 == 0){
                    System.out.println("User 1 and User 2 cross each other in between room " + result + " and room " + (result+1));
                }
                else{
                    System.out.println("User 1 and User 2 meets in room " + (result + 1));
                }
            }
        }
        else{
            System.out.println("Rooms count should be more than zero");
        }
    }

}
Comments: