Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7.2, Problem 7.2.11CP
What is the output of the following code?
- 1. public class Test {
- 2. public static void main(String[] args)
- 3. int 1ist [] = { 1 . 2 , 3 , 4 , 5, 6} ;
- 4. for (int i = 1; i < list.length ; i++)
- 5. list[i] = list[i- 1] ;
- 6.
- 7. for (int i= 0; i < list.length; i++ )
- 8. System.out .print(list[i] + " " );
- 9. }
- 10. }
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
class Solution(object):
def longestCommonPrefix(self, strs):
result =""
for i in strs[0]:
for j in strs[1]:
for k in strs[2]:
if i == j and i == k:
result+=i
if len(result) >0:
return result
else:
return result
IndexError: list index out of range for j in strs[1]: Line 5 in longestCommonPrefix (Solution.py) ret = Solution().longestCommonPrefix(param_1) Line 31 in _driver (Solution.py) _driver() Line 41 in <module> (Solution.py)
can someone explain why this is wrong?
void listEmployees (void)
{
for (int i=0; i 10000.
Make a guess about why the comparison function takes 2 struct Employee
parameters (as opposed to struct Employee *)
**
Instructions
Insurance.java
>- Terminal
+
1 import java.util.Scanner;
sandbox $ 0
2 class Insurance {
The Harrison Group Life Insurance company computes
public static void main (String args[]) {
// Write your code here
annual policy premiums based on the age the customer
4
turns in the current calendar year. The premium is
}
computed by taking the decade of the customer's age,
adding 15 to it, and multiplying by 20.
7
public static int calculatePremium(int curr, int birth) {
8
// Write your code here
}
For example, a 34-year-old would pay $360, which is
calculated by adding the decades (3) to 15, and then
10 }
11
multiplying by 20.
Write an application that prompts a user for the current
year then a birth year. Pass both to a method that
calculates and returns the premium amount, and then
display the returned amount.
An example of the program is shown below:
Enter the current year >> 2020
Enter the birth year >> 2001
The premium is $320
Grading
Write your Java code in the area on the…
Chapter 7 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 7.2 - Prob. 7.2.1CPCh. 7.2 - Prob. 7.2.2CPCh. 7.2 - What is the output of the following code? int x =...Ch. 7.2 - Indicate true or false for the following...Ch. 7.2 - Which of the following statements are valid? a....Ch. 7.2 - Prob. 7.2.6CPCh. 7.2 - What is the array index type? What is the lowest...Ch. 7.2 - Write statements to do the following: a. Create an...Ch. 7.2 - What happens when your program attempts to access...Ch. 7.2 - Identify and fix the errors in the following code:...
Ch. 7.2 - What is the output of the following code? 1....Ch. 7.4 - Will the program pick four random cards if you...Ch. 7.5 - Use the arraycopy method to copy the following...Ch. 7.5 - Prob. 7.5.2CPCh. 7.7 - Suppose the following code is written to reverse...Ch. 7.8 - Prob. 7.8.1CPCh. 7.8 - Prob. 7.8.2CPCh. 7.9 - Prob. 7.9.1CPCh. 7.9 - Prob. 7.9.2CPCh. 7.10 - If high is a very large integer such as the...Ch. 7.10 - Prob. 7.10.2CPCh. 7.10 - Prob. 7.10.3CPCh. 7.11 - Prob. 7.11.1CPCh. 7.11 - How do you modify the selectionSort method in...Ch. 7.12 - What types of array can be sorted using the...Ch. 7.12 - To apply java.util.Arrays.binarySearch (array,...Ch. 7.12 - Show the output of the following code: int[] list1...Ch. 7.13 - This book declares the main method as public...Ch. 7.13 - Show the output of the following program when...Ch. 7 - (Assign grades) Write a program that reads student...Ch. 7 - (Reverse the numbers entered) Write a program that...Ch. 7 - (Count occurrence of numbers) Write a program that...Ch. 7 - (Analyze scores) Write a program that reads an...Ch. 7 - (Print distinct numbers) Write a program that...Ch. 7 - (Revise Listing 5.1 5, PrimeNumber.java) Listing...Ch. 7 - (Count single digits) Write a program that...Ch. 7 - (Average an array) Write two overloaded methods...Ch. 7 - (Find the smallest element) Write a method that...Ch. 7 - Prob. 7.10PECh. 7 - (Statistics: compute deviation) Programming...Ch. 7 - (Reverse an array) The reverse method in Section...Ch. 7 - Prob. 7.13PECh. 7 - Prob. 7.14PECh. 7 - 7 .15 (Eliminate duplicates) Write a method that...Ch. 7 - (Execution time) Write a program that randomly...Ch. 7 - Prob. 7.17PECh. 7 - (Bubble sort) Write a sort method that uses the...Ch. 7 - (Sorted?) Write the following method that returns...Ch. 7 - (Revise selection sort) In Listing 7 .8, you used...Ch. 7 - (Sum integers) Write a program that passes an...Ch. 7 - (Find the number of uppercase letters in a string)...Ch. 7 - (Game: locker puzzle) A school bas 100 lockers and...Ch. 7 - (Simulation: coupon collectors problem) Coupon...Ch. 7 - (Algebra: solve quadratic equations) Write a...Ch. 7 - (Strictly identical arrays) The arrays 1ist1 and...Ch. 7 - (Identical arrays) The arrays 1ist1 and 1ist2 are...Ch. 7 - (Math: combinations) Write a program that prompts...Ch. 7 - (Game: pick four cards) Write a program that picks...Ch. 7 - (Pattern recognition: consecutive four equal...Ch. 7 - (Merge two sorted Lists) Write the following...Ch. 7 - (Partition of a list) Write the following method...Ch. 7 - Prob. 7.33PECh. 7 - (Sort characters in a string) Write a method that...Ch. 7 - (Game: hangman) Write a hangman game that randomly...Ch. 7 - (Game: Eight Queens) The classic Eight Queens...Ch. 7 - Prob. 7.37PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify your answer to the previous exercise so that the message includes the value of your budget if the price ...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
The following algorithm is designed to print the beginning of what is known as the Fibonacci sequence. Identify...
Computer Science: An Overview (12th Edition)
What Visual Basic function would you use to get the current time from the system, without the date?
Starting Out With Visual Basic (7th Edition)
Assume hbox is an HBox container: // This code has an error! hbox.setAlignment(CENTER);
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Explain forward-only cursors. Give an example of their use.
Database Concepts (8th Edition)
Describe the purpose of the access key attribute and how it supports accessibility.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In Java list all the values of the array after the function is called A. static void Fun(int[][]list){ int temp=list[1][2]; list[1][2]=list[0][2]; list[0][2]=temp; } public static void main(String[] args) { int [][]arr={{10,20,30},{100,200,300}}; Fun(arr); } 10,20,30,300 B. static void Fun(int[]list) { list[3]=5;} public static void main(String[] args) { int []arr={5,6,7,9}; Fun(arr); } C. static void Fun(int[][]list){ list[1][0]=0;} public static void main(String[] args) { int [][]arr={{-2,-3,-4},{5,6,7,9}}; Fun(arr); }arrow_forward7. (* =: 'a In this problem, you will determine what the following method does. public static void rra(int[] list, int start, int end) { if (start >= end) { return; } int tmp = list[start]; list [start] = list[end] = tmp; list[end]; // recursion! rra(list, start+1, end-1); } Suppose list = [0, 2, 4, 6, 8, 10, 12, 14, 16]. (a) ) W= ta . What happens to list when rra(list, 0, 4) is called? Show memory diagrams and/or stack frames to explain what the recursive calls are. (b) (в) с oj What happens to list when rra(list, 0, list.length - 1) is called? st Show memory diagrams and/or stack frames to explain what the recursive calls are.arrow_forwardQUESTION 2 public static double buyGroceries (String list) a. Identify the return type: b. Identify the parameter variable: c. This method i int double boolean String buyGroceries QUESTION 3 list value-receiving value-returning value-receiving and value-returning Analyze these lines public static ir sum (n1, parameterless answer void char liolk Soarrow_forward
- 1. task: Introduction and basics. Peter Zmeda is really lucky. He often finds parts of code and he then asks himself if he could use them anywhere. This time he has found the following code: int FooBar (A) { n= len (A); B= newArray (n) for j:= 0 to n-1 { } B[j] = 0 for i:= j to 0 step -1 { if A[i]arrow_forwardPython: Take your searching and sorting functions and put them into a class. The constructor should take a list as a parameter use the classes sort method and store the sorted list in a class property. A "search" method should return true or false if the item is found. A "count" method should return 0 or the number of times the item is found. For fun, you can create a method to generate a list of random numbers (and then sort it).arrow_forwardIt is a class that is part of the java.util package which can store a list of values and reference them with an index. (a) None of the Choices (b) Variable List (c) Array List (d) Object List Please provide an explanation. Thank you!arrow_forward// JAVA program to calculate the average score // import utility class for list collectionimport java.util.*; // class definitionpublic class Main{// main methodpublic static void main(String[] args) { // Variable declarationchar middle_initial;int id;double score1, score2, score3, average;String first_name, last_name, choice; // Scanner to read user inputsScanner sc = new Scanner(System.in); // integer counter to count number of studentsint counter = 0; // run a do-while loop until the user enters N or Nodo{// prompt user to enter first name, middle initial, and last nameSystem.out.print("Enter student's First Name:");first_name = sc.next();System.out.print("Enter student's Middle Initial:");middle_initial = sc.next().charAt(0);System.out.print("Enter student's Last Name:");last_name = sc.next(); // Add fullName of student in the Name listName.add(first_name + "." + middle_initial + "." + last_name); // enter idSystem.out.print("Enter student's Id:");id = sc.nextInt(); // add Id…arrow_forwardvoid funi (int iist , int s) { int sum=0; for (int i = 0; iarrow_forwardpublic class ShoppingListDriver{ public static void main(String[] args){ ShoppingList sl=new ShoppingList(3);sl.insert(null);sl.insert(new Item("Bread", "Carb Food", 2, 2.99));sl.insert(new Item("Seafood","Sea Food", -1, 10.99));sl.insert(new Item("Rice", "Carb Food",2, 19.99));sl.insert(new Item("Salad Dressings","Dessing", 2, 19.99));sl.insert(new Item("Eggs", "Protein",2, 3.99));sl.insert(new Item("Cheese","Protein", 2, 1.59));sl.insert(new Item("Eggs", "Protein",3, 3.99));sl.printNames();sl.print(); System.out.println("After removing Eggs:");sl.remove(new Item("Eggs","Protein",0,0));sl.printNames();sl.print(); }}arrow_forwardmain.cpp:4:17: error: 'string' has not been declared 4 | void KMPSearch(string pat, string txt) main.cpp:4:29: error: string' has not been declared 4 | void KMPSearch(string pat, string txt) Aununun main.cpp:31:25: error: string' has not been declared 31 | void computelPSArray(string pat, int M, int[] lps) main.cpp:31:50: error: expected or . before lps' 31 | void computeLlPSArray(string pat, int M, int[] lps) main.cpp:55:8: error: expected :' before 'static' 55 | public static void Main() main.cpp:61:2: error: expected ;' after class definition 61 | } | main.cpp: In member function 'void GFG::KMPSearch(int, int)': main.cpp:6:15: error: request for member Length' in 'pat', which is of non-class type 'int' 6 | int M = pat.Length; main.cpp:7:15: error: request for member Length' in txt’, which is of non-class type 'int' int N = txt.Length; main.cpp:8:6: warning: structured bindings only available with -std3c++17' or (-std=gnu++17' 8 | int[] lps new int[M];arrow_forwardPlease answer the question in the screenshot. The language used here is in Java.arrow_forward1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 } write the signature of the method sum: sum(int,int) *Method name/parameter list list local variables of sum: x, y, and y are local variables of the function. list the parameters of sum: int x, int y write the line number where a call to sum occurs 7 list the arguments for the above call list the return type of sum here ______________arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY