Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
In Java please.
Transcribed Image Text:Write a program that reads two lists of integers from input into two arrays and outputs the sum of multiplying the corresponding list items.
The program first reads an integer representing the length of each list, followed by two lists of integers.
Ex: If the input is:
3
1 2 3
3 2 1
the program calculates (1 * 3) + (2 * 2) + (3 * 1) and outputs
10
Ex: If the input is:
2 3 4 5
1 1 1 1
the program calculates (2 * 1) + (3 * 1) + (4 * 1) + (5 * 1) and outputs
14
Transcribed Image Text:1 import java.util.Scanner;
2
3 public class LabProgram {
4
5
6
7
8
9
10
11
12
13
14}
public static void main(String[] args) {
}
Scanner scnr new Scanner(System.in);
int size;
size = scnr.nextInt();
int[] listA new int[size];
int[] listB
new int[size];
here. */
=
/* Type your code
Develop mode Submit mode
// List A
// List B
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
Enter program input (optional)
If your code requires input values, provide them here.
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 4 steps with 3 images
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
How do i fix this code
Transcribed Image Text:This image illustrates an error encountered in a Java program due to the misuse of the `Scanner` class. The section at the top shows the Java code, which appears to be working on a mathematical computation involving two arrays `a` and `b`. Here’s a breakdown of each segment:
### Java Code:
- The code initializes variables and inputs data to perform mathematical operations.
- Key sections include the calculation of a `sum`, where each pair of elements from two arrays (`a` and `b`) are multiplied and accumulated.
### Inputs and Errors:
- Users are instructed to enter inputs in the provided box. Example inputs shown are `1 2 3` and `3 2 1`.
- When attempting to run the program, users encounter `Program errors displayed here`:
#### Error Details:
1. **Error Message:**
- `LabProgram.java:11: error: cannot find symbol len = sc.nextInt();`
- **Symbol**: variable `sc`
- **Location**: class `LabProgram`
2. **Repetitive Errors:**
- Similar errors occur at line 15 and line 18, indicating `sc` is used without being properly initialized.
3. **Nature of Errors:**
- The errors suggest that the `Scanner` object `sc` has not been declared. This is essential for capturing user input in Java programs.
- Solution: Declare `Scanner sc = new Scanner(System.in);` at the beginning of the class to resolve these errors.
### Workflow Diagram:
- A workflow diagram illustrates the flow from input gathering to processing through `LabProgram.java` and output generation.
### Conclusion:
These errors need addressing by declaring and initializing the `Scanner` object properly so that inputs can be read and processed without issues. Understanding these common mistakes is crucial for beginners learning Java programming.
Solution
Bartleby Expert
by Bartleby Expert
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
How do i fix this code
Transcribed Image Text:This image illustrates an error encountered in a Java program due to the misuse of the `Scanner` class. The section at the top shows the Java code, which appears to be working on a mathematical computation involving two arrays `a` and `b`. Here’s a breakdown of each segment:
### Java Code:
- The code initializes variables and inputs data to perform mathematical operations.
- Key sections include the calculation of a `sum`, where each pair of elements from two arrays (`a` and `b`) are multiplied and accumulated.
### Inputs and Errors:
- Users are instructed to enter inputs in the provided box. Example inputs shown are `1 2 3` and `3 2 1`.
- When attempting to run the program, users encounter `Program errors displayed here`:
#### Error Details:
1. **Error Message:**
- `LabProgram.java:11: error: cannot find symbol len = sc.nextInt();`
- **Symbol**: variable `sc`
- **Location**: class `LabProgram`
2. **Repetitive Errors:**
- Similar errors occur at line 15 and line 18, indicating `sc` is used without being properly initialized.
3. **Nature of Errors:**
- The errors suggest that the `Scanner` object `sc` has not been declared. This is essential for capturing user input in Java programs.
- Solution: Declare `Scanner sc = new Scanner(System.in);` at the beginning of the class to resolve these errors.
### Workflow Diagram:
- A workflow diagram illustrates the flow from input gathering to processing through `LabProgram.java` and output generation.
### Conclusion:
These errors need addressing by declaring and initializing the `Scanner` object properly so that inputs can be read and processed without issues. Understanding these common mistakes is crucial for beginners learning Java programming.
Solution
Bartleby Expert
by Bartleby Expert
Knowledge Booster
Background pattern image
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 C/C++, pointers are employed. Why don't pointers exist in Java?arrow_forwardWhere exactly should I use dynamic typing as opposed to static type?arrow_forwardSome languages support many modes of parameter passing. Provide 2 examples using two different programming languages which support the user of the programming language deciding which to use when creating their method. (Programming Languages)arrow_forward
- Which of the following has data abstraction but not an abstract data type? C C++ Java C#arrow_forwardWhat would you expect to be the level of use of pointers in C#? How often will they be used when it is not absolutely necessary?arrow_forwardIn C/C++, pointers are employed. Why is it that Java doesn't use pointers?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education