3 ms·
Why does ChatGPT does errors in basic programs?
Input:-
in java , what does this print
int x=3;
int y =3;
int z = 3;
if(x <=z)
{
System.out.print(z);
z=4;
}
if (z>y){
x= 2;
System.out.print(x);
}
else{
System.out.print(z<x);
}
Chatgpt’s response :- In Java, the code int x = 3, y = 3; int z = 3; if(x <= z){System.out.print(z);z = 4;}if (z > y){ x = 2; System.out.print(x);}else{System.out.print(z < x);} will print "33".
First, the condition in the first if statement is true because x (3) is less than or equal to z (3), so the first statement System.out.print(z); will print 3.
Next, the condition in the second if statement is false because z (4) is not greater than y (3), so the else block is executed and the expression z < x is evaluated and printed.
Since z is 4 and x is 3, z < x is false, which is a boolean value that will be printed as "false".
So the final output will be "33".
Expected output :-32
I’m wondering why is it assuming 4 is not greater than 3 here “Next, the condition in the second if statement is false because z (4) is not greater than y (3), so the else block is executed”
- gjvc 4y agoFeels like an anti-plagiarism feature, albeit perhaps not one which is working perfectly yet.
- mailltestpy 4y agoHaha ! I agree it seems like an anti plagiarism feature.
- oifjsidjf 4y agoBecause it's an regurgitation algorithm which is capable of multiple levels of abstractions. It understands nothing. It cannot do reasoning. It's possible it might develop a reasoning "part" if the parameters and training are specified in a certain way, but even then it will be up to chance if it develops a sub-part of it's abstraction mechanism that will actually be able to do pure logic without just guessing smartly what should come next.
- mailltestpy 4y agoIt understands to certain extent . I made it realize (asked if 4>3) it’s mistake and it’s response now:- “I apologize, my previous response was incorrect. The else block in the Java program you provided will not execute because the condition z > y is true, resulting in the execution of the code inside the if block, which sets x = 2 and prints 2. The else block will not be executed.”
- dtagames 4y agoNo, it didn't recognize or fix its error. It simply added your statement to the "body of truth" and then wrote a new answer which includes what you said and explains it based on the previous content of the thread.
- dtagames 4y agoChatGPT can only assemble words in the most likely order that they might appear in context. It works better with prose than code, but ChatGPT does not understand programming and cannot run the source to see if it works. It's much like a robot version of searching for the most likely code on StackOverflow and copy/pasting that. I wrote an intro about how it works and how all these seemingly illogical "errors" keep showing up. I'd love your feedback. https://medium.com/gitconnected/behind-the-curtain-understanding-the-magic-of-chatgpt-3bbd23f0fbb3 https://medium.com/gitconnected/behind-the-curtain-understan...
- dtagames 4y agoForgot to mention: GitHub Copilot can do what you want. If you write your prompt as comments (one on each line) to tell it what you want the program to do, it can get much closer than ChatGPT because it works somewhat differently and also was trained on more programming language code than ChatGPT. I wrote an intro on this, too. :-) https://medium.com/gitconnected/flying-with-github-copilot-cab566ee5d9 https://medium.com/gitconnected/flying-with-github-copilot-c...