37 ASSIGNMENT OPERATOR VS EQUAL TO OPERATOR

 package com.cnc;

public class Main {
public static void main(String[] args) {

int newValue =50;
if (newValue = 50){ //we are not assigning the value
System.out.println("this is an error");
}
int newValue1 =50;
if (newValue1 == 50){ //we are not assigning the value but we are testing if newValue1 is equal to 50 or not
System.out.println("Error is removed by using == in newValue1");
}

boolean isCar = false;
if ( isCar = true){
System.out.println("This is not supposed to happen in car");
}
boolean isCar1 = false;
if ( isCar1 == true){
System.out.println("This is fine and we are using == sign in car1 ");
}
boolean isCar2 = false;
if (!isCar2){
System.out.println("This is fine and we are using ! sign in car2 ");
}

}
}


Error is removed by using == in newValue1
This is not supposed to happen in car
This is fine and we are using ! sign in car2

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY