Computer Science, asked by alabotharampavan01, 9 months ago

What is the output of this program?
class selection statements {
public static void main(String args[])
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == vari)
System.out.print(var2);
else
System.out.print(++var2);
}
}​

Answers

Answered by Anonymous
4

Compilation error.... vari not defined.

if mean var1..

then the output is

2

Answered by codiepienagoya
8

Output of the given code:

output:

2

Explanation:

In the given program that is some typing mistake, so the correct code to this question as follows:

Program:

public class selection_statements //defining selection_statements class

{

public static void main(String ar []) //defining main method

{

int var1 = 5; //defining variable integer variable var1

int var2 = 6; //defining variable integer variable var1

if ((var2 = 1) == var1) // defining condition block to check value

System.out.print(var2);//print value

else

System.out.print(++var2); //print value

}

}

Explanation:

  • In the above code, two integer variable "var1 and var2" is declared that holds a value "5 and 6".
  • In the next step, if condition statement is used in this first variable var2 is assign a value that is 1 and check it is equal to var1. If it is true it will print var2 value.  
  • In else section, it will increment the value of var2 then prints its value.

Learn more:

  • How to write a java program: https://brainly.com/question/12948823

Similar questions