Temperatures puzzle discussion

Hey, i am very grateful for your help.
Without you, I really wouldn’t have got the 100% score.
Thank you

Submission test include “-273 alone” does this mean inputs were tested as [-273,‘alone’] or [-273]

Is “alone” a temperature?

Can bad data be sent to an app? Do you present tests in other games with bad data?

yes

“alone” is in the test’s name, not in the data itself.

hi, I not anderstand what I do incorect. if I copy this conditions in Intellij IDEA - my code is work. but in this site - not…

class Solution {

public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int result1 =5526;
    int result2 =-273;
    int result =0;
    int n = in.nextInt(); // the number of temperatures to analyse
    for (int i = 0; i < n; i++) {
        int t = in.nextInt(); // a temperature expressed as an integer ranging from -273 to 5526
        
        if (result1>t){
            result1=t;
        }
        if (result2<t){
            result2=t;
        }
        
   }
//   System.out.println(result1);
//   System.out.println(result2);
   
   if (result1<(result2*(-1))){
        result=result1;
    }else {
        result=result2;
    }
    // Write an answer using System.out.println()
    // To debug: System.err.println("Debug messages...");

    System.out.println(result);
}

}

What does “not work” mean? Runtime error? Incorrect result?
btw did you add the import headers?

1 Like

Incorect result

Have you tried reading the different testcases input and expected output to better understand what your program is supposed to do ?

Based on your code, I guess your answer for Testcase 1 (the example in the statement) is -8.
The expected solution is 1.

You should try to solve the given testcases by hand, you will then understand why your code gives the wrong answer.

1 Like

I not understand what you mean “You should try to solve the given testcases by hand”… I only study but this code I write ftom my mind. If I copy code - I want, I note have qwestins.
and I seach number in Array with random in Intellij IDEA (+ or-), and Intellij I have result is good.
NOT i not read the different testcases input and expected output, if I understand why my code is wrong, I read this. Maybe you have good article - please write me URL or article/
thank’s.

Check external resources linked in the puzzle description.

You can use debug display in your code to better understand why code you think works does not. Try and add this at the end of your for loop :

System.error.println(i + " : t = " + t + " / result1 = " 
                 + result1 +  " / result2 = " + result2);
1 Like

It’s a good advice, meaning you should try to execute your code with a paper and a pen, writing all variable’s values at each round of your loop. And checking if it is what you expected.

2 Likes

@cg123, @hemhel thanks… I understan why my code is wrong. in programming need be very careful.I updete my if second condition.
THANK’S

There is an error with last question in C++ :slightly_frowning_face:

No, your script has an error, not the puzzle.

This puzzle shows a different result compared to Visual Studio. Do you think this puzzle IDE is better than Microsoft things?

Most likely explanations: not the same inputs; unspecified behavior in your code.

Remember Clippy. Or Windows ME.

Joke aside, at the end of the day, it’s not VS judging your attempt.

if (result1>t && t > 0){
result1 = t;
}
if (result2< && t < 0{
result2=t;
}

Make a desktop test and you’ll see why

1 Like

Keep getting failed messages even though your output seems right?
Remove all output lines INCLUDING the “Result” line put in by default as that’s blocking the pass.
Spent 30 minutes with right answers trying to figure out what the heck was wrong :joy:

Hi, I think there is still a problem with the XP attribution after completing the puzzle.
I’ve 100% but 0/2 Success and no XP …
I solved the puzzle in C#. Thanks for checking