5: Compare output a Output differs. See highlights below. 54 6.02 Input m Bye Enter integer: Enter double: Enter character: Your output Enter string: 54 6.02 m Bye Bye m 6.02 54 6.02 cast to an integer is 6.02 Enter integer: Enter double: Enter character: Expected output Enter string: 54 6.02 m Bye Bye m 6.02 54 6.02 cast to an integer is 6

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
Using JavaScript Im trying to find the problem with my last code at ( FixMe (3): ) The userDouble doesn’t show in my output as an integer I need some help turning that double to an integer
O https://fayted
CSC151 TeterSpring2022/chapter/2/section/35
e > 2.35: LAB: Warm up: Variables, input, and casting
32.2042412.gx3zgy7
AB
CTIVITY
2.35.1: LAB: Warm up: Variables, input, and casting
Basiclnput.java
Load defa
1 import java.util.Scanner;
3 public class BasicInput {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userInt;
double userDouble;
4
5.
6
// FIXME Define char and string variables similarly
Character userInput;
String userWord;
8
10
11
12
13
System.out.println("Enter integer:");
userInt = scnr.nextInt();
14
15
16
System.out.println("Enter double:");
userDouble = scnr.nextDouble();
17
18
19
System.out.println("Enter character:");
userInput = scnr.next().charAt (0);
20
21
System.out.println("Enter string:");
userWord - scnr.next();
22
23
24
25
// FIXME (1): Finish reading other items into variables, then output
//the four values on a single line separated by a space
System.out.println(userInt +
26
27
+ userDouble + "|
+ userInput + " "
+ userWord);
28
// FIXME (2): Output the four values in reverse
System.out.println(userWord +
29
30
+ userInput +
+ userDouble +
+ userInt);
31
// FIXME (3): Cast the double to an integer, and output that integer
System.out.println(userDouble + '
32
33
+ "cast to an integer is" +
+ userDouble);
34
35
36 }
When done developing your program, press the Submit for grading button below.
submit your program for auto-grading.
Develop mode
Submit mode
Suhmit for aredinn
Fz
Transcribed Image Text:O https://fayted CSC151 TeterSpring2022/chapter/2/section/35 e > 2.35: LAB: Warm up: Variables, input, and casting 32.2042412.gx3zgy7 AB CTIVITY 2.35.1: LAB: Warm up: Variables, input, and casting Basiclnput.java Load defa 1 import java.util.Scanner; 3 public class BasicInput { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int userInt; double userDouble; 4 5. 6 // FIXME Define char and string variables similarly Character userInput; String userWord; 8 10 11 12 13 System.out.println("Enter integer:"); userInt = scnr.nextInt(); 14 15 16 System.out.println("Enter double:"); userDouble = scnr.nextDouble(); 17 18 19 System.out.println("Enter character:"); userInput = scnr.next().charAt (0); 20 21 System.out.println("Enter string:"); userWord - scnr.next(); 22 23 24 25 // FIXME (1): Finish reading other items into variables, then output //the four values on a single line separated by a space System.out.println(userInt + 26 27 + userDouble + "| + userInput + " " + userWord); 28 // FIXME (2): Output the four values in reverse System.out.println(userWord + 29 30 + userInput + + userDouble + + userInt); 31 // FIXME (3): Cast the double to an integer, and output that integer System.out.println(userDouble + ' 32 33 + "cast to an integer is" + + userDouble); 34 35 36 } When done developing your program, press the Submit for grading button below. submit your program for auto-grading. Develop mode Submit mode Suhmit for aredinn Fz
ome> 2.35: LAB: Warm up: Variables, input, and casting
Enter double:
Enter character:
Your output
Enter string:
99 3.77 z Howdy
Howdy z 3.77 99
3.77 cast to an integer is 3.77
Enter integer:
Enter double:
Enter character:
Expected output
Enter string:
99 3.77 z Howdy
Howdy z 3.77 99
3.77 cast to an integer is 3
5: Compare output a
Output differs. See highlights below.
54
6.02
Input
m
Bye
Enter integer:
Enter double:
Enter character:
Your output
Enter string:
54 6.02 m Bye
Bye m 6.02 54
6.02 cast to an integer is 6.02
Enter integer:
Enter double:
Enter character:
Expected output
Enter string:
54 6.02 m Bye
Bye m 6.02 54
6.02 cast to an integer is 6
Transcribed Image Text:ome> 2.35: LAB: Warm up: Variables, input, and casting Enter double: Enter character: Your output Enter string: 99 3.77 z Howdy Howdy z 3.77 99 3.77 cast to an integer is 3.77 Enter integer: Enter double: Enter character: Expected output Enter string: 99 3.77 z Howdy Howdy z 3.77 99 3.77 cast to an integer is 3 5: Compare output a Output differs. See highlights below. 54 6.02 Input m Bye Enter integer: Enter double: Enter character: Your output Enter string: 54 6.02 m Bye Bye m 6.02 54 6.02 cast to an integer is 6.02 Enter integer: Enter double: Enter character: Expected output Enter string: 54 6.02 m Bye Bye m 6.02 54 6.02 cast to an integer is 6
Expert Solution
Step 1

Explanation :-

Here is your problem with code at ( FixMe (3): ) The userDouble doesn’t show in your output as an integer because you don't convert the userDouble to integer by casting .

See how convert  the double value into integer.

userDouble + " " + "cast to an integer is" + " " + (int)userDouble

And you use userDouble instead of (int)userDouble.

See the below complete code with an output.

 

 
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Unary Predicate
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education