Concept explainers
Explanation of Solution
Given code segment:
int number; //Line 1
String str = "99"; //Line 2
//Convert str to an int
number = str.parseInt(); //Line 3
Errors in the above program:
Error #1:
In the above code segment, “Line 3” contains an error. The parse methods are used to convert the string to a number. The method accepts string as its argument. The method “parseInt ()” does not contains any argument. Hence the line should be given as:
//Convert str to an int
number = str.parseInt(str); //Line 3
Error #2:
In the above code segment, “Line 3” contains an error. If the user wants to convert the string to integer then the syntax to convert the given string to integer is as follows.
int variableName = Integer.parseInt(String stringObject);
Therefore, “str.parseInt ()” should be written as “Integer.parseInt ()”.
Corrected program:
//Import required header files
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.text...
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out with Java: Early Objects, Student Value Edition (6th Edition)
- 'Q1 Write a {pmgram that reads 10 numbers and then finds the latgest number and prints it and finds the smallest number and prints it.arrow_forwardvoid funOne(int a, int& b, char v); void main() { int num1=10; char ch='A'; funOne(num1, 15,ch)<arrow_forwardFix the errors and find the lowest marks entered by the user struct std{string name;int reg_no;int marks[5];}s1;getline(cin,s1.name);cin>>s1.reg_no;for(int i =0;i<5;i++)cin>>s1.marks[i]arrow_forwardC. #include int main() { char name[20]; printf("\nEnter your name :"); gets (name) ; printf("\nYour name is "); puts(name); }arrow_forwardint x1 = 66; int y1 = 39; int d; _asm { } mov EAX, X1; mov EBX, y1; push EAX; push EBX; pop ECX mov d, ECX; What is d in decimal format?arrow_forward. COMPLETE THE CODES.arrow_forwardvar adventurersName = ["George", " Tim", " Sarah", " Mike", " Edward"];var adventurersKilled = 3;var survivors;var leader = "Captain Thomas King";var numberOfAdventurers = adventurersName.length; survivors = numberOfAdventurers - adventurersKilled; console.log("Welcome to The God Among Us\n");console.log("A group of adventurers began their search for the mystical god said to live among us. In charge of the squad was " + leader + " who was famous for his past exploits. Along the way, the group of comrades were attacked by the god's loyal followers. The adventurers fought with bravado and strength under the tutelage of "+ leader + " the followers were defeated but they still suffered great losses. After a headcount of the remaining squad, "+ adventurersKilled +" were found to be dead which left only " + survivors + " remaining survivors.\n"); console.log("Current Statistics :\n");console.log("Total Adventurers = " + numberOfAdventurers);console.log("Total Killed = " +…arrow_forwardint grades[100]; int i; for (i=0;i <= 100;i++) { grades[i) = 100; } The above C++ code is the proper way to initialize the grades array, TRUE or FLASE True Falsearrow_forwardComplete the code: string cars[5] = {"Volvo", "BMW", "Ford", "Mazda", "Honda"}; for(int i = 0; i < - ; i++) { cout << cars[i]< "\n"; } %3Darrow_forwardchar[ ] letters=new char[5];int x = 0;while(x < 10){ar[x]='a';x++;}arrow_forwardJAVA:arrow_forwardTreasure Hunter description You are in front of a cave that has treasures. The cave canrepresented in a grid which has rows numbered from 1to , and of the columns numbered from 1 to . For this problem, define (?, )is the tile that is in the -th row and -column.There is a character in each tile, which indicates the type of that tile.Tiles can be floors, walls, or treasures that are sequentially representedwith the characters '.' (period), '#' (hashmark), and '*' (asterisk). You can passfloor and treasure tiles, but can't get past wall tiles.Initially, you are in a tile (??, ). You want to visit all the treasure squares, andtake the treasure. If you visit the treasure chest, then treasurewill be instantly taken, then the tile turns into a floor.In a move, if you are in a tile (?, ), then you can move tosquares immediately above (? 1, ), right (?, + 1), bottom (? + 1, ), and left (?, 1) of thecurrent plot. The tile you visit must not be off the grid, and must not be awall patch.Determine…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- 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