Question

What is the proper syntax for Boolean statements? Why does this not work? int firstNumber =...

What is the proper syntax for Boolean statements?

Why does this not work?

int firstNumber = 2;

int secondNumber = 3;

if (firstNumber = secondNumber) {...}

But this does work?

if (firstNumber == secondNumber) {...}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

== IS equality Operator
= IS ASSIGNMENT


=> if (firstNumber = secondNumber) {...}

Explanation :
Here firstNumber becomes 2 , if(2) has no meaning it should be like if(false) or if(true) otherwise we will get Syntax error

=> if (firstNumber == secondNumber) {...}
Explanation :
Here we do equality which results in true or false . Hence There is no sysntax error



THANKS, PLEASE UPVOTE

Add a comment
Know the answer?
Add Answer to:
What is the proper syntax for Boolean statements? Why does this not work? int firstNumber =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • After the following declarations and statements are executed:       int i, j, k ;       boolean...

    After the following declarations and statements are executed:       int i, j, k ;       boolean c;       float x, y,   z;       int[ ] num = {4, 1, 2, 3, 8};       i = 3;       j = 5;       x = 4.3;       y = 58.209;       c = !(i > j) ; what is the value of c

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...

  • 8.What is the proper syntax for malloc a.What is Malloc’s parameter b.What does sizeofdo? 9.If I...

    8.What is the proper syntax for malloc a.What is Malloc’s parameter b.What does sizeofdo? 9.If I want to provide new memory to a pointer that already has memory allocated to it, what must I do before I rerun “malloc” on the pointer?

  • Question 11 (3 points) What does the following recursive method determine? public boolean question 16(int[]a, int[]...

    Question 11 (3 points) What does the following recursive method determine? public boolean question 16(int[]a, int[] b. intj) { if (j == 2.length) return false; else if ( == b.length) return true; else return question 16(2, b.j+1): 3 returns true if b contains less elements than a, false otherwise returns true if b contains more elements than a, false otherwise returns true if a and bare equal in size, false otherwise returns true if a's element value is larger than...

  • 3. Use EBNF to describe the syntax of Java while statements, no need to further define...

    3. Use EBNF to describe the syntax of Java while statements, no need to further define other statements or Boolean expressions.

  • JAVA 5) What is the output of the following code? int a = 70; boolean b...

    JAVA 5) What is the output of the following code? int a = 70; boolean b = false; if(a >= 70) { System.out.print(1); if(b==true) { System.out.print(2); } } else { System.out.print(3); if(b==false) { System.out.print(4); } } System.out.print(5); 6) What is the output of the code above using these initial values? int a = 43; boolean b = false; 7) The following method is SYNTACTICALLY correct (meaning it will compile). True or false? public boolean method() { int value = 5;...

  • 2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo...

    2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?

  • In Java, Assume we have these two methods. public static boolean allAreEqual(int n1, int n2, int...

    In Java, Assume we have these two methods. public static boolean allAreEqual(int n1, int n2, int n3) { return n1 == n2 && n2 == n3; } public static boolean mystery(int n1, int n2, int n3) { return !allAreEqual(n1, n2, n3) && (n1 == n2 || n1 == n3 || n2 == n3); } Part 1: What value will be returned by the following method calls? mystery(5, 5, 5) mystery(5, 5, 1) Part 2: What does the mystery method do...

  • 3 a) Design a search method using proper Java syntax with the signature shown below. Assume...

    3 a) Design a search method using proper Java syntax with the signature shown below. Assume the books are stored in a stack (i.e., can only access an element before another after you pop the top). You can document any other assumptions you make using Java comments within the code Note. You can only access an element below another element by popping the stack. public Book Search (int ISBN)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT