Question

1. What is the type of the argument for the main method? 2. Given the following...

1. What is the type of the argument for the main method?

2. Given the following declaration, what is the type of myString[1]?

String myString[][] = new String[2][3];

3.Given the following declaration, what is the value of foo[2][1]?

int foo[][] = {{10,20,30,40}, {50,60,70, 80, 90}, {100,110,120}}

4. What is wrong with the following code?

int foo[] = new int [5];

for (int i = 0; i <= 5; i++)

{

foo[i] = 0;

}

5. What is one advantage of the ArrayList over a standard array?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1)
String[]

2)
String[]

3)
int

4)
for loop is trying to access foo[5], but that's not possible because size of array is 5. and hence the valid indexes are only from 0 to 4.

5)
ArrayLists can dynamically grow in size, while arrays can't.
Add a comment
Know the answer?
Add Answer to:
1. What is the type of the argument for the main method? 2. Given the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.The following statement gets an element from position 4 in an array named myArray: x =...

    1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...

  • 1) Write a public static method named printArray, that takes two arguments. The first argument is...

    1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...

  • Write a static method named sumOf that takes an array of int values as an argument...

    Write a static method named sumOf that takes an array of int values as an argument (you may safely assume that the array contains at least 1 element). This method should return the sum of all values in the array. Examples: Given the following array declaration and definition. int[] theArray = {0, 0, 0, 0, 0, 0}; sumOf(theArray) will return 0 Given the following array declaration and definition. int[] theArray = {1, 1, 1, 1, 1, 1}; sumOf(theArray) will return...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • IN JAVA please Given a sorted array and a target value, return the index if the...

    IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • Those questions are about Java. Question 2 Which of the following is NOT a wrapper class?...

    Those questions are about Java. Question 2 Which of the following is NOT a wrapper class? Integer Double String Character Flag this Question Question 3 Which of the following kinds of things may be stored directly in an ArrayList? None of the above primitive values Either of these two kinds of data object references Flag this Question Question 4 In this declaration: ArrayList<Point> polygon; what do we call 'Point'? a type argument a wrapper class a collection a variable Flag...

  • What output is produced by the following code? Explain how it works. 1.1 1 ...2..... 5...

    What output is produced by the following code? Explain how it works. 1.1 1 ...2..... 5 package taesik; import java.util.; /* Your name: Date: Answer: How it works: */ class student String name; int age; 1 public class Quiz21 ( public static void main(String args[])! ArrayList<student>myArray = new ArrayListo(); for(int i=0; i< 6; i++) { student s = new student(); s.name="Emily" ; 3.ageri; myArray.add(s); 1 for (int i = 0; i <myarray.size(); i++) { System.out.format($s $den", myArray.get(i).name, myArray.get(i)-age); } System.out.println();...

  • Please help me finish my code. Before the final pause in the main function, create an...

    Please help me finish my code. Before the final pause in the main function, create an ArrayList of another type such as double, char, short, bool, float, etc. Your choice. Add five data items to your array as we did for the int and string array lists. Print them out with a for loop as we did before. Print out the count and capacity of your new array list. Source.cpp #include #include #include #include "ArrayList.h" using namespace std; /// Entry...

  • 1. Given the following code, how many references exist to the Time object at the end...

    1. Given the following code, how many references exist to the Time object at the end of the main method and what are their names? public class Foo { public static void main(String args[]) { Time t = new Time(); Time t1 = t; Time t2 = t; Clock clock = new Clock(t); // AT THIS POINT, HOW MANY REFERENCES TO THE TIME OBJECT ARE THERE } } public class Time { } public class Clock { private Time time;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT