Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 1, Problem 3P
Explanation of Solution
Purpose of the given code:
The given code is to product the two numbers and displays the result.
Syntax error:
An error which is occurred on the source code of a program is referred as “syntax error”; because the computer programs are strictly follows the syntax rules, if the code fails to prove its language syntax format then the compiler will throws an error.
Error in the given code:
n1=keyboard.nextInt();
n2=keyboard.nextInt();
The variables “n1” and “n2” are not declared in the given statement. Hence, it throws the syntax error.
Corrected code:
//Import required package
import java.util...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I receive the following errors when I try running and compiling the code. Ive attached the following image involving the errors.
In the following code explain all the errors that would prevent the program from compiling correctly. (C++)
How many different objects of type integer exist in the computer’s memory after the following code has been executed? Assume that no garbage collection has been executed and that no optimizations have been performed. (Python)
x, y = 5, 10
x = x * 5
y = x
z = 5
A) 3
B) 6
C) 4
D) 5
E) 2
Chapter 1 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 1.1 - What are the two kinds of memory in a computer?Ch. 1.1 - What is software?Ch. 1.1 - What data would you give to a program that...Ch. 1.1 - What data would you give to a program that...Ch. 1.1 - What is the difference between a program written...Ch. 1.1 - Is Java a high-level language or a low-level...Ch. 1.1 - Is Java bytecode a high-level language or a...Ch. 1.1 - What is a compiler?Ch. 1.1 - What is a source program?Ch. 1.1 - What do you call a program that translates Java...
Ch. 1.2 - What would the following statement, when used in a...Ch. 1.2 - Write a statement or statements that can be used...Ch. 1.2 - Prob. 13STQCh. 1.2 - What is the meaning of the following line in the...Ch. 1.2 - Write a complete Java program that uses system....Ch. 1.2 - Suppose you define a class named YourClass in a...Ch. 1.2 - Prob. 17STQCh. 1.3 - What is a method?Ch. 1.3 - Prob. 19STQCh. 1.3 - Do all objects of the same class have the same...Ch. 1.3 - Prob. 21STQCh. 1.3 - Prob. 22STQCh. 1.3 - Prob. 23STQCh. 1.3 - Prob. 24STQCh. 1.3 - What is an algorithm?Ch. 1.3 - What is pseudocode?Ch. 1.3 - Prob. 27STQCh. 1.3 - Prob. 28STQCh. 1.3 - Prob. 29STQCh. 1.3 - Prob. 30STQCh. 1.3 - Prob. 31STQCh. 1.3 - Suppose you write a program that is supposed to...Ch. 1.4 - Prob. 33STQCh. 1.4 - Prob. 34STQCh. 1 - How does a computers main memory differ from its...Ch. 1 - Prob. 2ECh. 1 - Prob. 3ECh. 1 - How does machine language differ from Java?Ch. 1 - What would the following statements, when used in...Ch. 1 - Write a statement or statements that can be used...Ch. 1 - Write statements that can be used in a Java...Ch. 1 - Given a persons year of birth, the Birthday Wizard...Ch. 1 - Write statements that can be used in a Java...Ch. 1 - Prob. 11ECh. 1 - Prob. 12ECh. 1 - Prob. 13ECh. 1 - Prob. 14ECh. 1 - What attributes and behaviors would an object...Ch. 1 - Suppose that you have a numberxthat is greater...Ch. 1 - Prob. 17ECh. 1 - Prob. 18ECh. 1 - Prob. 19ECh. 1 - Prob. 20ECh. 1 - Obtain a copy of the Java program shown in Listing...Ch. 1 - Modify the Java program described in Practice...Ch. 1 - Prob. 3PCh. 1 - The following program will compile but it has...Ch. 1 - Programming Projects require more problem-solving...Ch. 1 - Write a complete program for the problem described...Ch. 1 - Prob. 3PPCh. 1 - Prob. 4PPCh. 1 - Write an applet program for the problem described...Ch. 1 - Prob. 6PP
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
- What will be output to the screen when the following code is executed:def PrintMe(x): try: return s * 5 except: print("Error has occured") finally: print("Doing some cleanup")arrow_forwardWhat is the printout of running the program in (a)? What problem arises in compiling the program in (b)?arrow_forwardNote:- Please type and execute this java program and also please upload the output of the code with it. Also, say with what name file need to be saved.arrow_forward
- What will happen when the following program is compiled and run? #include<stdio.h>int main(){int a[]={1,2,3,4,5};int b[]={1,2,3,4,5};if(a==b){printf("yes");}else{printf("no");}return 0;} A. yesB. noC. The program will encounter a compilation error.D. There will be a runtime error in the program.arrow_forwardIf you forget to declare the variable i in the following, what kind error will be raised? c++ while (i <= 9) cout << "hi"; A. a compilation error B. a runtime error C. a logic error D. no errorarrow_forwardIn Python: What gets printed by executing the following code?arrow_forward
- This is a debugging question - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Code I was given - // A byte can't hold a value higher than 127 // This program throws an ArithmeticException // if adding two bytes yields a value that is too high public class DebugTwelve2 { public static void main(String[] args) { byte num1 = 120, num2 = 120, result; final byte HIGHBYTE = 127; try { allowed = (byte)(HIGHBYTE - num1); if(num2 > allowed) throw(new Arithmeticexception()); result = (byte)(num1 + num2); System.out.println("Result is + result); } catch(ArithmeticcException error) { System.out.println("Byte can't hold value higher than " + HIGHBYT); } } }arrow_forwardHere is the question: The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Here is the code given: // Program prompts user to enter a series of integers // separated by spaces // Program converts them to numbers and sums them import java.util.*; public class DebugSeven2 { public static void main(String[] args) { String str; int x; int length; int start; int num; int lastSpace = -1; int sum = 0; String partStr; Scanner in = new Scanner(System.in); System.out.print("Enter a series of integers separated by spaces >> "); str = in.nextLine(); length = str.length(); for(x = 0; x <= length; ++x) { if(str.charAt(x) == ' ') { partStr = str.substring(lastSpace + 1); num =…arrow_forwardPlease use java to complete this programarrow_forward
- In Python: What gets printed by executing the following code? def teststrings():str1 = 'X University'str2 = 'Computer Science'print(str1[0].isupper()) #str3 = str1.replace("university',' ')str2+=' ' +str1print(str1)print(str3.rstrip())print(str2)def main():teststrings()main()arrow_forwardNote:- Please study than type and execute this java code and also give output for this java program as soon as possible. Also please save with what name to save the file.arrow_forwardQUESTION One of the downsides of using expressions that produce results other than true or false is it is expensive to type-check it hurts readability since it may be confusion to know which route an execution will take. it can cause side effects skewing the results of the rest of the code it hurts writability since we have to write such long expressions.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning