which of the following declarations is INCORRECT?A. String s = "Hi!";B. int[] ar = new int(3);C. double d = 1.3E + 21;D. double d = 1.3D;
Question
Which of the following declarations is INCORRECT?
A. String s = "Hi!";
B. int[] ar = new int(3);
C. double d = 1.3E + 21;
D. double d = 1.3D;
Solution
To determine which of the following declarations is incorrect, let's analyze each option step by step:
A. String s = "Hi!"; This declaration is correct. It creates a String variable named "s" and assigns it the value "Hi!".
B. int[] ar = new int(3); This declaration is incorrect. The correct syntax to create an array and specify its size is "new int[3]". Therefore, the correct declaration would be: int[] ar = new int[3];
C. double d = 1.3E + 21; This declaration is correct. It creates a double variable named "d" and assigns it the value 1.3 multiplied by 10 raised to the power of 21 (1.3 x 10^21).
D. double d = 1.3D; This declaration is correct. It creates a double variable named "d" and assigns it the value 1.3.
Therefore, the incorrect declaration is option B. int[] ar = new int(3).
Similar Questions
Which of the following is incorrect? Group of answer choicesint[] a = new int[2];All are correctint[][] a = new int[2];int a[] = new int[2];
Which one of the following declarations is correct?Select one:int long;char int;int length;float double;
Analyze the following code and choose the correct answer.int[] arr = new int[5];arr = new int[6];
Which of the following declaration is not supported by C language?String str;Both “String str;” and “float str = 3e2;”float str = 3e2;char *str;Clear my choice
Which of the following can be used to declare a floating-point variable in Java?floatdoubleBoth float and doubleNeither float nor doub
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.