Question

In: Computer Science

Given the following Java source code fragment double price[]; price = new double[16]; What's the name...

Given the following Java source code fragment double price[]; price = new double[16]; What's the name of the array? How many elements are in the array? What's the index of the first element in the array? What's the index of the last element in the array? What's the value of the element at index 3 after the last statement executes?

Solutions

Expert Solution

1. Answer:

Name of the array is price.

2. Answer:

The size of array describes the number of elements in the array.

Here, the size is declared in [ ] square brackets & the size is 16. Hence, it can hold 16 elements.

3.Answer:

Index is the address of the elements stored in an array.

Indexing always starts from zero (0)

Hence, the index of the first element is 0. (zero).

4. Answer:

The last index is size of the array minus 1.(Since, indexing starts from zero).

Therefore, the index of last element in the array is 15 .(16-1=15).

5. Answer:

Initially, since no values are assigned to the array, the default values for the "double" data type is assigned. Hence upon trying to print the value at index 3, use the following java code :

System.out.println(price[3]);

It will print 0.0 as output.

==============END OF THE ANSWER==============


Related Solutions

Determine the output using C++ of the following code fragment i) double *pt; double a[3] =...
Determine the output using C++ of the following code fragment i) double *pt; double a[3] = {1.2, 2.3, 3.4}; pt = &a[1]; pt += 1; cout << *pt << endl; ii) int i = 1; while (i <= 4) { int num = 1; for (int j = 1; j <= i; j++) { cout << num << "bb"; num *= 3; } cout << endl; i++; }
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;...
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;     int quantity;     bool equals(const Product&); }; how would you define the equals function so two products are equal if their names and prices are equal? a. bool equals(const Product& to_compare) {     return (name == to_compare.name && price == to_compare.price); } b. bool Product::equals(const Product& to_compare) {     return (name == to_compare.name || price == to_compare.price); } c. bool equals(const Product& to_compare)...
Given the following code fragment: x = (1,2,3) Match the syntax with the action: value =...
Given the following code fragment: x = (1,2,3) Match the syntax with the action: value = x{0} (a) value is bound to the value 1 (b) SyntaxError: invalid syntax (c) TypeError: 'tuple' object is not callable value = x(0) (a) value is bound to the value 1 (b) SyntaxError: invalid syntax (c) TypeError: 'tuple' object is not callable value = x[0] (a) value is bound to the value 1 (b) SyntaxError: invalid syntax (c) TypeError: 'tuple' object is not callable
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double)...
Java Create an abstract Product Class Add the following private attributes: name sku (int) price (double) Create getter/setter methods for all attributes Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the building object that is formatted nicely and contains all information (attributes) Create a FoodProduct Class that extends Product Add the following private attributes: expDate (java.util.Date) for expiration date refrigerationTemp (int) if 70...
What is the output of the following piece of Java code? int id = 4; double...
What is the output of the following piece of Java code? int id = 4; double grossPay = 81.475; String jobType = "Intern"; System.out.printf("Id: %d, Type: %s, Amount:%.2f", id,grossPay,jobType); Select one: Error Id: 4, Type: Intern, Amount: $81.475 Id: 4, Type: $81.475, Amount: Intern Id: 4, Type: $81.48, Amount:Intern Id: 4, Type: Intern, Amount: $81.48
Implement Java source code for a class called Temperature that does the following: a. Prompts the...
Implement Java source code for a class called Temperature that does the following: a. Prompts the user to input a temperature b. Prints “Too Hot!” when the input temperature is above 75 c. Prints “Too Cold!” when the input temperature is below 40 d. Prints “Just Right!” when the input temperature is 40 to 75 e. Be precise, include comments, prologue, etc. if needed.
I need a flow chart built in raptor and the Java source code in the source...
I need a flow chart built in raptor and the Java source code in the source folder (src) Please fully document the program: add comments to describe all major parts of the solution. SO that I can understand how and why the code was built that way. Problem specifications: -The TSA want you to design and code a program that will be used to screen travelers through AirportX. When a traveler arrives at the airport, he/she is required to go...
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner...
in java my code double price[] = {26.99, 22.99, 13.99, 56.99, 38.99}; // Variable Declaration Scanner keyIn = new Scanner(System.in); //Header System.out.println( "----------------------------------------\n" + " Grocery Shop Price Calculator \n" + "----------------------------------------\n") ; System.out.print ("Please enter the quantities for each item in the list? "); double totalCost = 0; double fishAmount = 0; for(int i=0; i<price.length; i++) { int items = Integer.parseInt(keyIn.nextLine()); if(i==4) fishAmount = price[i]*items; else totalCost = totalCost + price [i]*items; } System.out.print("Do you have the membership(Y/N) ");...
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code...
This is a programming assignment!!! Start with the Assignment3.java source code posted to Canvas. This code outputs the programmer’s name , prompts the user to enter two numbers (integers) and outputs their sum. Note: When you run the program, it expects you to enter two integer values (a counting or whole number like 1, 216, -35, or 0) Make the following changes/additions to the code: On line 11, change the String myName from “your full name goes here!!!” to your...
Code in Java 1. Create a class Flower with data: Name, Price, Color and properly methods....
Code in Java 1. Create a class Flower with data: Name, Price, Color and properly methods. 2. Create another class named ListFlower. This class manages a collection of Flower (may be LinkedList) named a. Implementing some methods for ListFlower: Add: add new item of Flower to a Display: display all items of a sort(): sort as descending by Price and display all items of a search(Flower f): check and return whether f is exists in a or not. delete(int pos):...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT