Knowee
Questions
Features
Study Tools

Which of the following statements are valid?a. int i = new int(30);b. double d[] = new double[30];c. char[] r = new char(1..30);d. int i[] = (3, 4, 3, 2);e. float f[] = {2.3, 4.5, 6.6};f. char[] c = new char()

Question

Which of the following statements are valid?a. int i = new int(30);b. double d[] = new double[30];c. char[] r = new char(1..30);d. int i[] = (3, 4, 3, 2);e. float f[] = {2.3, 4.5, 6.6};f. char[] c = new char()

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

Solution

The valid statements from the given options are:

b. double d[] = new double[30]; This is a valid statement in Java. It declares an array of doubles with a size of 30.

e. float f[] = {2.3, 4.5, 6.6}; This is a valid statement in Java. It declares an array of floats and initializes it with the values 2.3, 4.5, and 6.6.

The invalid statements are:

a. int i = new int(30); This is not a valid statement. In Java, you don't use the new keyword to initialize an integer.

c. char[] r = new char(1..30); This is not a valid statement. In Java, the correct syntax to declare an array is new char[30], not new char(1..30).

d. int i[] = (3, 4, 3, 2); This is not a valid statement. In Java, you should use curly braces {} to initialize an array, not parentheses ().

f. char[] c = new char(); This is not a valid statement. In Java, when you declare an array with the new keyword, you need to specify the size of the array in square brackets [].

This problem has been solved

Similar Questions

Which one of the following is a valid statement? char[] c = new char();char[] c = new char[5]; char[] c = new char(4); char[] c = new char[];

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;

Which of the following are incorrect? Please select all that apply. Group of answer choicesint[] a = new int[2];int a[] = new int[2];int[] a = new int(2);int a = new int[2];int a() = new int[2];

Which of the following statements would produce a True result given this code?char s1[] = "alpha";char s2[] = "alpha";char s3[] = "beta";char s4[] = "gamma";Select one:a.strcmp(s1, s2);b.strcmp(s1, s3);c.strcmp(s3, s4);d.strcmp(s1, "Alpha");

Which one of the following declarations is correct?Select one:int long;char int;int length;float double;

1/3

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.