in Education by
If logic given below works well in C language but it doesn't work in java....Why..?? It gives an error in java while compiling. class test { public static void main(String[] args) { int i; if(i=4) System.out.println("hello"); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You need to use the comparison operator (==) instead of the assignment operator (=) in your if statement. In C, the result of a valid assignment operator is the value that is assigned. If your example was in C, the resultant code would be equivalent to if(4), which evaluates to a true statement, and the code is always executed without any complaints by the compiler. Java checks for a few cases where you probably mean something else, such as this one.

Related questions

0 votes
    If logic given below works well in C language but it doesn't work in java....Why..?? It gives ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    If logic given below works well in C language but it doesn't work in java....Why..?? It gives ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    If logic given below works well in C language but it doesn't work in java....Why..?? It gives ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Let's say, I have a folder called maps and inside maps I have map1.txt, map2.txt, and map3.txt. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    Basically i have a java String which i want to restrict all the characters other than this regex code ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    We have a library where users can pass in dates in multiple formats. They follow the ISO but are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Is it possible to add the numbers 1 to n recursively in Java with one return statement? How would ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have to copy classpath resource from one package to another. My program is: public static void main( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have an abstract class Product public abstract class Product implements Serializable { private Integer id; private ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have a user interface in .net which needs to receive data from a server, on a request/reply/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I have a dilemma, I'm using Java and Oracle and trying to keep queries on PL/SQL side. Everything ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    Anyone know if it is possible to write an app that uses the Java Sound API on a system that doesn ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Is there a Java package providing funcionality like the .Net System.Data namespace ? Specificaly the DataSet ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
...