Knowee
Questions
Features
Study Tools

Select the INCORRECT initialization of values for the variables ‘a’ and ‘b’?int a = 32, b = 40.6;int a = 42; b = 40;int a = 32; int b = 40;int a = b = 42;int a =30 b=40;

Question

Select the INCORRECT initialization of values for the variables ‘a’ and ‘b’?int a = 32, b = 40.6;int a = 42; b = 40;int a = 32; int b = 40;int a = b = 42;int a =30 b=40;

🧐 Not the exact question you are looking for?Go ask a question

Solution 1

The incorrect initializations of values for the variables 'a' and 'b' are:

  1. int a = 32, b = 40.6; - This is incorrect because 'b' is being assigned a floating point number (40.6), but it is declared as an integer. In Java, you cannot assign a floating point number to an integer variable.

  2. int a =42; b = 40; - This is incorrect because 'b' is not declared before it is assigned a value. In Java, you must declare a variable before you can assign it a value.

  3. int a =30 b=40; - This is incorrect because there is no semicolon (;) after the initialization of 'a'. In Java, each statement must end with a semicolon.

This problem has been solved

Solution 2

The incorrect initializations of values for the variables 'a' and 'b' are:

  1. int a = 32, b = 40.6; - This is incorrect because 'b' is initialized with a floating point number (40.6), but it is declared as an integer. In Java, you cannot assign a floating point number to an integer variable.

  2. int a =42; b = 40; - This is incorrect because 'b' is not declared before it is initialized. In Java, you must declare a variable before you can use it.

  3. int a =30 b=40; - This is incorrect because there is no semicolon (;) between the initializations of 'a' and 'b'. In Java, you must end each statement with a semicolon.

This problem has been solved

Similar Questions

Select the correct answerWhich of the given options correctly outlines the steps to exchange the values of two variables a and b without using a temporary variable in C?OptionsSet a equal to b, Set b equal to a, Initialize a to 5 and b to 10.Initialize a to 5 and b to 10, Set a equal to a plus b, Set b equal to a minus b, Set a equal to a minus b.Set b equal to a plus b, Set a equal to b minus a, Set b equal to a minus b.Initialize a to 10 and b to 5, Set a equal to a minus b, Set b equal to b plus a, Set a equal to b minus a.Finish ClearPrev Next

Select the correct answerWhich of the following is a valid way to initialize a constant in C?Optionsconstant x = 5;int const x = 5;const int x = 5;int x = const 5;

Which of the following are invalid statements.*1 pointint Scanner = 45;int Class = 45;int main = 45;int If = 45;None of the above

Observe the following function declaration and choose the best answer:int divide ( int a, int b = 2 )Select one:Variable b is of integer type and will always have value 2Variable a and b are of  type int and the initial value of both the variables is 2Variable b will have value 2, unless specified while calling the functionVariable b is global and will have value 2

Which one of the following is correct way of declaring and initialising a variable, x withvalue 5?int x, x=5int x=5x = 5declare x=5

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.