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
Textbook Question
Chapter 2, Problem 11E
What does the Java code
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a string.");
int n – keyboard.nextInt ();
String s = keyboard.next ();
System.out.println("n is" + n);
System.out.println("s is" + s);
display when the keyboard input is 2istheinput ?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
answer it
// DebugFive4.java
// Outputs highest of four numbers
import java.util.*;
public class DebugFive4
{
publicstaticvoidmain (Stringargs[])
{
Scanner input =newScanner(System.in);
int one, two, three, four;
String str, output;
System.out.println("Enter an integer");
str = input.next();
one = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
two = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
three = Integer.parseInt(str);
System.out.println("Enter an integer");
str = input.next();
four = Integer.parseInt(str);
if(one > two > one > three > one > four)
output = "Highest is " + four;
else
if(two > one && two > three !! two > four)
output = "Highest is " + three;
else
if(three > one && three > two && three > four)
output = "Highest is " + three;
else
output = "Highest is " + four;
System.out.println(output);
}
}
// Displays five random numbers between
// (and including) user-specified values
import java.util.Scanner;
public class DebugSix4
{
publicstaticvoidmain(String[] args)
{
int high, low, count =0;
finalint NUM =5;
Scanner input =newScanner(System.in);
System.out.print("This application displays " + NUM +
" random numbers"+
"\nbetween the low and high values you enter"+
"\nEnter low value now... ");
low = input.nextInt()
System.out.print("Enter high value... ");
high = inputnextInt();
while(low < high)
{
System.out.println("The number you entered for a high number, " +
high + ", is not more than " + low);
System.out.print("Enter a number higher than " + low + "... ");
high = input.nextInt();
while(count <NUM)
{
double result = Math.random();
int answer = (int) (result *10+ low);
if(answer <= higher)
{
System.out.print(answer + " ");
++count;
}
}
System.out.println("End of Application");
}
}
Chapter 2 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 2.1 - Prob. 1STQCh. 2.1 - Can a Java program have two different variables...Ch. 2.1 - Prob. 3STQCh. 2.1 - Give the declaration for two variables of type...Ch. 2.1 - Write the declaration for two variables called...Ch. 2.1 - What is the normal spelling convention for named...Ch. 2.1 - Prob. 7STQCh. 2.1 - Prob. 8STQCh. 2.1 - Prob. 9STQCh. 2.1 - Prob. 10STQ
Ch. 2.1 - Prob. 11STQCh. 2.1 - In the Programming Tip entitled Type Casting a...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - What is the output produced by the following lines...Ch. 2.1 - Prob. 15STQCh. 2.1 - Prob. 16STQCh. 2.1 - Consider the following statement from the program...Ch. 2.1 - Prob. 18STQCh. 2.2 - Prob. 19STQCh. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What output is produced by the following...Ch. 2.2 - What is the value of the expression sl.equals(s2)...Ch. 2.2 - What is the value of the expression s1.equals (s2)...Ch. 2.3 - Write Java statements that will cause the...Ch. 2.3 - What is the difference between the methods...Ch. 2.3 - Write a complete Java program that reads a line of...Ch. 2.3 - Write a complete Java program that reads one line...Ch. 2.3 - What output is produced by the following...Ch. 2.4 - Prob. 32STQCh. 2.4 - What is the output produced by the following Java...Ch. 2.4 - Although it is kind of silly, state legislatures...Ch. 2.5 - Prob. 35STQCh. 2.5 - Give a Java statement that will display a dialog...Ch. 2.5 - Give a Java statement that, when executed, will...Ch. 2.5 - Prob. 38STQCh. 2.5 - Write a complete Java program that produces a...Ch. 2.5 - Write a complete Java program that behaves as...Ch. 2 - Write a program that demonstrates the approximate...Ch. 2 - Write a program that demonstrates type casting of...Ch. 2 - Write a program that demonstrates the operator %...Ch. 2 - If u = 2, v = 3, w = 5, x = 7, and y = 11, what is...Ch. 2 - What changes to the ChangeMaker program in Listing...Ch. 2 - If the int variable x contains 10, what will the...Ch. 2 - Write some Java statements that use the String...Ch. 2 - Prob. 8ECh. 2 - Prob. 9ECh. 2 - Write a single Java statement that will display...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - What does the Java code Scanner keyboard = new...Ch. 2 - Prob. 13ECh. 2 - Many sports have constants embedded in their...Ch. 2 - Prob. 15ECh. 2 - Define named constants that you could use in...Ch. 2 - Write a program that reads three whole numbers and...Ch. 2 - Write a program that uses Scanner to read two...Ch. 2 - Write a program that reads the amount of a monthly...Ch. 2 - Write a program that reads a four-digit integer,...Ch. 2 - Prob. 5PCh. 2 - Prob. 6PCh. 2 - Write a program that converts degrees from...Ch. 2 - Write a program that reads a line of text and then...Ch. 2 - Write a program that will read a line of text as...Ch. 2 - Write a program that asks the user to enter a...Ch. 2 - Write a program that determines the change to be...Ch. 2 - Write a program that reads a 4-bit binary number...Ch. 2 - Prob. 7PPCh. 2 - The Harris-Benedict equation estimates the number...Ch. 2 - Repeat any of the previous programming projects...Ch. 2 - Write a program that reads a string for a date in...Ch. 2 - It is important to consider the effect of thermal...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (8th Edition)
The command from the JDK compiles a Java program.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
The following function accepts an i nt argument and returns half of its value as a double: double half(int numb...
Starting Out with C++ from Control Structures to Objects (9th Edition)
What are the four basic arithmetic operations?
Digital Fundamentals (11th Edition)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Does the is a relationship work in reverse? Why or why not?
Starting out with Visual C# (4th Edition)
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
- // ArtShow.java - This program determines if an art show attendee gets a 5% discount // for preregistering. // Input: Interactive. // Output: A statement telling the user if they get a discount or no discount. import java.util.Scanner; public class ArtShow { public static void main(String args[]) { Scanner s = new Scanner(System.in); String registerString; System.out.println("Did you preregister? Enter Y or N: "); registerString = s.nextLine(); // Test input here. If Y, call discount(), else call noDiscount(). System.exit(0); } // End of main() method. // Write discount method here. // Write noDiscount method here. } // End of ArtShow class.arrow_forwardFind the errors in the following code:// This code contains ERRORS!int choice, num1, num2;Scanner keyboard = new Scanner(System.in);do{System.out.print("Enter a number: ");num1 = keyboard.nextInt();System.out.print("Enter another number: ");num2 = keyboard.nextInt();System.out.println("Their sum is " + (num1 + num2));System.out.println("Do you want to do this again? ");System.out.print("1 = yes, 0 = no ");choice = keyboard.nextInt();} while (choice = 1)arrow_forwardPrint "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forward
- JAVA Input. class Modulus { publicstaticvoid main(String args[]) { double a =25.64; int b =25; a = a % 10; b = b % 10; System.out.println(a +" "+ b); } } Find output.arrow_forwardclass Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}} What will the given code prints on the output screen.arrow_forward// This program assigns values to two variables // and performs mathematical operations with them public class DebugFour1 { publicstaticmain(Stringargs[]) { int x =5 int y =8; System.out.println("adding " + x + y); int z =19; System.out.println("subtracting " + z - y); System.out.println("dividing " + z / x); System.out.println("multiplying " + x / z); } }arrow_forward
- public String getJoblitle() { return joblitle; 11 12 13 44 45 46 47 48 49 50 public void setJoblitle(String joblitle) { this.jobTitle - joblitle; public int getCurrentEmploynent() { return currentEmploynent; 1. public void selCurrentEnployent (int current Fmployment) { this.currentEmploynent - currentEmployment; 53 54 55 56 -57 goverride public String tostring () { return "CurrentEmploynentStatsclass [areaName=" + arealame + 58 + "year=" + year + ", jobtitle-" + joblitle , currentEnploynent-" + currenttmployment + "]": 59 61 62 63 64 } What algorithm does this method perform? public statie Currentiploynentstatsclass mysteryethod (CurrentEmploynentstatsclass] array) ( int holder = array[0).getCurrenttmploynent(); Currenttmploynentstatsclass variable = array[®]; for(int i- 0, i holder) { holder = holderx; variable - array[1]; return variable; 36. What is the above method returning? 37. What is the Big O time of the above method?arrow_forwardpublic class Side Plot { * public static String PLOT_CHAR = "*"; public static void main(String[] args) { plotxSquared (-6,6); * plotNegXSquaredPlus20 (-5,5); plotAbsXplus1 (-4,4); plotSinWave (-9,9); public static void plotXSquared (int minX, int maxx) { System.out.println("Sideways Plot"); System.out.println("y = x*x where + minX + "= minX; row--) { for (int col = 0; col row * row; col++) { System.out.print (PLOT_CHAR); if (row== 0){ } System.out.print(" "); } for(int i = 0; i <= maxx* maxX; i++) { System.out.print("-"); } System.out.println(); Sideways PHOT y = x*x where -6<=x<=6 Sideways Plot y = x*x where -6<=x<=6 How do I fix my code to get a plot like 3rd picture?arrow_forwarddouble y = 3/ 2; System.out.println(y); displays O1 1.5arrow_forward
- // 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 { publicstaticvoidmain(String[] args) { String str; int x; int length; int start; int num; int lastSpace =-1; int sum =0; String partStr; Scanner in =newScanner(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, y); num = Integer.parseInt(partStr); System.out.println(" " + num); sum += number; lastSpace = x; } } partStr = str.substring(lastSpace + 1, length); num = Integer.parseInt(partStr); System.out.println(" " + num); sum += num; System.out.println(" -------------------" + "\nThe sum of the integers is "+ sum); } }arrow_forwardWrite an application that counts by five from 5 through 500 inclusive, and that starts a new line after every multiple of 50 (50, 100, 150, and so on). public class CountByFives { public static void main (String args[]) { // Write your code here } }arrow_forwardPlease include a gui for the encryption and decryption java code. Example of the gui in the photos Java encryption and decryption code below import java.util.*; public class Main { //Inputs a one character string and returns True if the character is a letter (i.e. a to z or A to Z). Returns false if it is not. A function to check that the password or encryption key is valid. public static boolean isALetter(char letter){ if( (letter >= 'a' && letter = 'A' && letter =-32767 && encryptKeyarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY