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 12.11, Problem 12.11.7CP
Suppose you enter 45 57, 8 789, then press the Enter key. Show the contents of the variables after the following code is executed:
Scanner input = new Scanner(System.in);
int intValue = input.nextInt();
double doubleValue = input.nextDouble();
String line = Input.nextLine();
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that allows the user to enter timein seconds in the text field and press the Enter key to count down the seconds,as shown in Figure d . The remaining seconds are redisplayedevery second.When the seconds are expired, the program starts to play musiccontinuously.
Prompt for the user to enter their name.
Print out their name forwards, backwards, vertically-forwards and vertically-backwards.
You will need to declare a String variable, use Scanner to get input of a String, call a String method to isolate one letter and create a loop that traverses the name forwards and backwards.
Sample Output:
Enter your name:
Florene
Florene
enerolF
F
l
o
r
e
n
e
e
n
e
r
o
l
F
HINTS:
Scanner input = new Scanner(System.in);
String myName = input.nextLine(); // input is a Scanner object
int len = myName.length() // len is the number of characters
System.out.println (myName.substring(len-1, len)); // prints last letter
I need help with coding the name "Pooja" vertically-forwards and vertically-backwards in java. If you could show me what codes to type in, that would be great. Thank you!
Suppose you enter 34.3 57.8 789, then press the ENTER key. Analyze the following code.
Scanner input = new Scanner(System.in);double v1 = input.nextDouble();double v2 = input.nextDouble();String line = input.nextLine();
A.
After the last statement is executed, line contains characters ' ', '7', '8', '9'.
B.
After the last statement is executed, line contains characters '7', '8', '9', '\n'.
C.
After the last statement is executed, line contains characters '7', '8', '9'.
D.
After the last statement is executed, line contains characters ' ', '7', '8', '9', '\n'
Chapter 12 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 12.2 - Prob. 12.2.1CPCh. 12.2 - Prob. 12.2.2CPCh. 12.2 - Prob. 12.2.3CPCh. 12.2 - Prob. 12.2.4CPCh. 12.2 - Prob. 12.2.5CPCh. 12.2 - Show the output of the following code:Ch. 12.3 - Prob. 12.3.1CPCh. 12.3 - Prob. 12.3.2CPCh. 12.4 - Prob. 12.4.1CPCh. 12.4 - Prob. 12.4.2CP
Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
In the following table, fill in the expected values returned by the ToString function when specific numeric val...
Starting Out With Visual Basic (7th Edition)
What will the following program display on the screen? #include iostream using namespace std; class Tank { priv...
Starting Out with C++: Early Objects (9th Edition)
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Suppose savings and expenses are variables of type double that have been given values. Write an if-else stateme...
Absolute Java (6th Edition)
The following code should print whether integer value is odd or even: 1 switch (value % 2) { 2 case 0: 3 System...
Java How To Program (Early Objects)
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
- can you check my code the wrong part based on the question below #include<iostream>using namespace std; struct Student { string name; double weight; double height; }; int main () { Student studentList [100]; //declare ofstream myfile; myfile.open ("studentData.txt"); ifstream infile; infile.open("studentData.txt"); //write into text file myfile<<"test 3"; //close file my file.close (); return 0; }arrow_forwardMany user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. i becomes ! a becomes @ m becomes M B becomes 8 o becomes . Ex: If the input is: Mypassword The output is: Myp@ssw.rdq*s Write a program to get the above task done. Use switch statement to handle the conditional part of the code.arrow_forwardAssuming a scanner variable has been initialized. To read an entire line of input into a string we write Group of answer choices scnr.read() scnr.next() scnr.nextLine() scnr.remove()arrow_forward
- Write an application that allows a user to enter any number of student test scores until the user enters 999. If the score entered is less than 0 or more than 100, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average. Save the file as TestScoreStatistics.cpp.arrow_forwardWhat is the output of the following code segment?inte=5,f=10;if(eff0) Write(Red); else Write(Orange);Â a. Red b. Orange c. RedOrange d. nothingarrow_forwardWhat will the following code display?try:x = float('abc123')print('The conversion is complete.')except IOError:print('This code caused an IOError.')except ValueError:print('This code caused a ValueError.')print('The end.')arrow_forward
- Find a line with an error in the following code segment: 1: void displayFile(fstream file) {2: string line;3: while (file >> line) 4: cout << line << endl;5: } Group of answer choices 1 2 3 4arrow_forwardPlease help!! I don't understand most of the code. Please leave comments as explanations on every line of the code. def repeatChar(numRepeats, outputChar):'''output the outputChar numRepeats times'''for colNo in range(numRepeats):print(outputChar, end='')def Parrallelogram(side, char):for i in range(side):repeatChar(i+1, char)print()for i in range(side):repeatChar(i+1, ' ')repeatChar(side-i-1, char)print()def outlineParallelogram(side, char):for i in range(side):if (i < 1):repeatChar(1, char)elif(i == 1):repeatChar(2, char)else:repeatChar(1, char)repeatChar(i-1, ' ')repeatChar(1, char)print()for i in range(side-1):if (i == side-2):repeatChar(side-1, ' ')repeatChar(1, char)else:repeatChar(i+1, ' ')repeatChar(1, char)repeatChar(side-i-3, ' ')repeatChar(1, char)print()print('This program will show a parallelogram and its outline')number = int(input('How long do you want each side to be? '))character = input('Enter the character: ')Parrallelogram(number,…arrow_forwardpublic static char start(char key) {Scanner console = new Scanner(System.in);String prompt = "Enter 'q' to quit. Any other key to continue...";double height;double weight;System.out.println("Enter something before you start : >>>>");while (key != 'q'){height = getHeight(console);weight = getWeight(console);displaySummary(height, weight);//prompt to quitSystem.out.println();System.out.print(prompt);key = console.next().charAt(0);}return key;} How can I test this one in the J-unit test?? Is it testable?arrow_forward
- What is wrong with the following code, if anything? Note: you may assume there are no syntax errors. int a=0;int count;ifstream iFile;int sum=0;iFile.open( "data.txt");if ( iFile.is_open() == false)return;elsedo{iFile>>a;sum += a;if ( iFile.eof())break;}while ( !iFile.eof() );cout << sum << endl;arrow_forwardJava- Write a program that prints out the calls for a spaceship that is about to launch. Write "Ready?", then write the numbers 10 down to 1, and then write "Liftoff!". You must use a loop. Don't use scanner object.arrow_forwardchange the code to do the same purpose and same output : Source Code: #include<iostream>#include<fstream>#include<string> using namespace std; void displayPlain();void displayHex(); void executeCommand(int choice){ switch (choice) { case 1: displayPlain(); break; case 2: displayHex(); break; case 9: exit(0); default: cout<<"Invalid Choice Entered!!\n"; }} void displayMenu(){ cout<<"\n===============Menu==========================\n\n"; cout<<"1. Select 1 to see file data in plain text\n"; cout<<"2. Select 2 to see file data in hexadecimal\n"; cout<<"3. Select 9 to quit\n\n";} int main(){ int choice; do{ displayMenu(); cout<<"choice: "; cin>>choice; executeCommand(choice); }while(choice != 9); return 0;} void displayPlain(){ fstream file; file.open("q4File.txt", ios::in); string line; if(file.is_open()){…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
C++ Programming Tutorial 36 - Intro to Loops; Author: Caleb Curry;https://www.youtube.com/watch?v=M3o7Y0juEP0;License: Standard YouTube License, CC-BY