Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
11th Edition
ISBN: 9780134671604
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 13.3, Problem 13.3.2CP
Program Plan Intro
Given Code:
//declaration of class
public abstract class ex1
{
//declaration of main method
public static void main(String[] args)
{
/*creation of an array of integer type named "numberArray" having size 2 */
Number[] numberArray = new Integer[2];
/*creation of a double object */
numberArray[0] = new Double(1.5);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In C++
Create an array of random 10 random numbers. Use the "range-based for loop" (sometimes called "enhanced for loop") to put the values into the array (users choice of number) and use the "range-based for loop" to output the numbers to the console.
In C++
Create an array of 100 random numbers between 1 and 1000. Ask the user for a number. Search the array and check if the users number is in the array.
#include <stdio.h>
int main(){ int arr[10]; int i; for (i=0; i<10; i++){ arr[i] = i; } for (i=0; i<10; i++){ printf("arr[%d] = %d\n", i, arr[i]); } return 0;}
Copy the code and modify it as follows:
Add another separate array of 10 integers. The following code parts are to be added (in the same order as specified) after the printing of the values of the first array:(1) Copy the content of the first array to the second array. Add 10 to each of the values of the second array. Make use of a single loop to achieve this part.(2) Print each element of the second array. Make use of another loop for this part
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Knowledge Booster
Similar questions
- If you run the following code through Valgrind, which of the following errors will be reported? Check all that apply. int main() { const int MAX_LENGTH = 10; int * myArray = new double[MAX_LENGTH]; for (int i = 0; i <= MAX_LENGTH; ++i) { cout << myArray[i]<< endl; } delete[] myArray; } Invalid read Invalid write Invalid free() Mismatched free() / delete / delete [] Mismatched free() / delete / delete Uninitialized value Memory leak None of the abovearrow_forwardMethod: sumOdds(value: int): This method will sum all the odd values from 1 upto the value passed by parameter. This will display the sumas an integer value.Method: characterCount(phrase: str): This method will count the number of characters in the phrase that is passed by parameter. You cannot useany built in function ( ie len() ) and must use a looping activity. This should display the number of characters inthe phrase as an integerMethod: multiplicationPractice(): This method is to practice simple multiplication problems. The program should randomly generate twonumbers from 1-10 for the user to multiply. It should display the multiplication problem and allow the user toanswer the problem. It should display if the user got the answer correct or incorrect. The activity shouldcontinue until the user has gotten 3 different practice problems correct.Method: order(value1: int, value2: int, value3: int): This method is to order the 3 passed value from least to greatest. It should display…arrow_forwardPlease help how to fix my code? My code! #include <stdio.h> struct Student{int id;char name[30];float percent;}; int main() {struct Student s[3];for(int i=0;i<3;i++){scanf("%d",&s[i].id);scanf("%s",s[i].name);scanf("%f",&s[i].percent);}for(int i=0;i<3;i++){printf("Records of Student %d",i+1);printf("\nID :%d",s[i].id);printf("\nName: %s",s[i].name);printf("\nPercentage :%.2f",s[i].percent);printf("\n");}return 0;}arrow_forward
- Explain following code segment:int [] a = new int [3];int [] b = new int [3];a = b;arrow_forward#include <stdio.h>#include <stdlib.h> typedef struct Number_struct { int num;} Number; void Swap(Number* numPtr1, Number* numPtr2) { /* Your code goes here */} int main(void) { Number* num1 = NULL; Number* num2 = NULL; num1 = (Number*)malloc(sizeof(Number)); num2 = (Number*)malloc(sizeof(Number)); int int1; int int2; scanf("%d", &int1); scanf("%d", &int2); Thank you so much but i forgot to put this how i would fit in into this. num1->num = int1; num2->num = int2; Swap(num1, num2); printf("num1 = %d, num2 = %d\n", num1->num, num2->num); return 0;}arrow_forwardWhat are the values of mynum[0], mynum [1], and mynum[2] after the following code executes? double[] mynum = new double[3]; double start = 1.5; for (double i : mynum) { i = start; start += 10.5; } а. 0.0 0.0 0.0 b. 1.5 12.0 22.5 с. 1.5 d. 22.5 1.5 1.5 22.5 22.5 e. Nothing will print due to an out of bounds errorarrow_forward
- def tpr(tp, fn): # TODO return def TEST_tpr(): tpr_score = tpr(tp=100, fn=1) todo_check([ (np.isclose(tpr_score,0.99009, rtol=.01),"tpr_score is incorrect") ]) TEST_tpr() garbage_collect(['TEST_tpr'])arrow_forwardWhat is the function of the following code?//code startconst size = 4;const ArrayOfSize = [];for (var i = 0; i < size; i++);{ArrayOfSize.push(i + 1);}ArrayOfSize;//code endarrow_forwardIn Python, grades = {'Tim': [87,96,70], 'Sue': [100,87,90], 'Jack': [94,77,90], 'Kevin': [100,81,82], 'Bart': [83, 65, 85]} Ask user to enter the names of the rows, i.e., indices. You can use: len(grades) to get the number of rows of the DataFrame. In addition, using the sort_index() method, ask user whether they wish to sort by rows or by columns and whether to sort in ascending or descending order (do not use any if-else statements) '''arrow_forward
- in java Integer numVals is read from input and integer array userCounts is declared with size numVals. Then, numVals integers are read from input and stored into userCounts. Output all elements of userCounts in reverse order, following each element with a space, including the last. After the final output, end with a newline. Ex: If the input is 4 54 56 75 7 then the output is: Array contents in reverse: 7 75 56 54 Note: The loop should start with i = userCounts.length - 1 and end with i = 0. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.Scanner; public class UserLog { publicstaticvoidmain(String[] args) { Scannerscnr=newScanner(System.in); intnumVals; inti; numVals=scnr.nextInt(); int[] userCounts=newint[numVals]; for (i=0; i<userCounts.length; ++i) { userCounts[i] =scnr.nextInt(); } System.out.print("Array contents in reverse: "); /* Your code goes here */ } }arrow_forwardWhat is the value of d['a'] after the following lines of code are executed? d = {} d['a'] = 1 2 = [,q.]p d['c'] = 3 d['a'] = 4arrow_forwardThis is needed in JAVAarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT