Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProblemA454 {
- public static void main(String agrs[]){
- Scanner sc = new Scanner(System.in);
- //puts all input into ints
- int papaBear = sc.nextInt();
- int mamaBear = sc.nextInt();
- int sonBear = sc.nextInt();
- int masha = sc.nextInt();
- boolean mashaFits = false;
- // array of all possible car sizes of bear
- int[] a = new int[sonBear+1];
- //puts all possible car sizes of bear inside array (size sonBear ... sonBear*2)
- for(int i = 0; i<a.length;i++){
- a[i] = sonBear + i;
- }
- for(int j = 0; j<a.length;j++){
- //masha fits is boolean if masha fits into son bear car for any array)
- if(!mashaFits){
- if(masha <= a[j] && a[j] <= (masha * 2)){
- System.out.println(papaBear);
- System.out.println(mamaBear);
- System.out.println(sonBear);
- //so for loop only runs once
- mashaFits = true;
- }
- }
- }
- //else print -1 as masha doesnt fit into any of son bears car values in array 1
- if(!mashaFits){
- System.out.println("-1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement