Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on this lab and no matter what I do I can't get this coding to work correctly. Please help!! Here's the assignment.
I am working on this lab and no matter what I do I can't get this coding to work correctly. Please help!! Here's the assignment. Variables, input, and casting Java Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. Submit for points Enter integer: Enter double: Enter character: z Enter string: Howdy z Howdy Extend to also output in reverse. Submit for point, so points total Enter integer: Enter double: Enter character: z Enter string: Howdy z Howdy Howdy z Extend to cast the double to an integer, and output that integer. Submit for points, so points total Enter integer: Enter double: Enter character: z Enter string: Howdy z Howdy Howdy z cast to an integer is Here's my input: not sure if this might be the problem z Howdy Here's my code: import java.util.Scanner; public class BasicInput public static void mainString args Scanner scnr new ScannerSystemin; int userInt ; double userDouble ; char userChar; String userString; System.out.printlnEnter integer:"; userInt scnrnextInt; System.out.printlnEnter double:"; userDouble scnrnextDouble; System.out.printlnEnter character:"; userChar scnrnextcharAt; System.out.printlnEnter string:"; userString scnrnext; System.out.printlnuserInt userDouble userChar userString; System.out.printlnuserString userChar userDouble userInt; int castedInt int userDouble; System.out.printlnCasting userDouble to an integer is castedInt; scnrclose; Here's the error that I am receiving: Output differs. See highlights below. Special character legend Input z Howdy :Compare output Your output starts with Enter integer: Enter double: Enter character: Enter string: z Howdy Howd Expected output starts with Enter integer: Enter double: Enter character: Enter string: z Howdy :Compare output Output differs. See highlights below. Special character legend Input A Plethora Your output starts with Enter integer: Enter double: Enter character: Enter string: A Plethora Plet Expected output starts with Enter integer: Enter double: Enter character: Enter string: A Plethora :Compare output Output differs. See highlights below. Special character legend Input z Howdy Your output starts with Enter integer: Enter double: Enter character: Enter string: z Howdy Howdy z Cast Expected output starts with Enter integer: Enter double: Enter character: Enter string: z Howdy Howdy z :Compare output Output differs. See highlights below. Special character legend Input z Howdy Your output Enter integer: Enter double: Enter character: Enter string: z Howdy Howdy z Casting to an integer is Expected output Enter integer: Enter double: Enter character: Enter string: z Howdy Howdy z cast to an integer is :Compare output Output differs. See highlights below. Special character legend Input m Bye Your output Enter integer: Enter double: Enter character: Enter string: m Bye Bye m Casting to an integer is Expected output Enter integer: Enter double: Enter character: Enter string: m Bye Bye m cast to an integer is
I am working on this lab and no matter what I do I can't get this coding to work correctly. Please help!!
Here's the assignment.
Variables, input, and casting Java
Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. Submit for points
Enter integer:
Enter double:
Enter character: z
Enter string: Howdy
z Howdy
Extend to also output in reverse. Submit for point, so points total
Enter integer:
Enter double:
Enter character: z
Enter string: Howdy
z Howdy
Howdy z
Extend to cast the double to an integer, and output that integer. Submit for points, so points total
Enter integer:
Enter double:
Enter character: z
Enter string: Howdy
z Howdy
Howdy z
cast to an integer is
Here's my input: not sure if this might be the problem
z
Howdy
Here's my code:
import java.util.Scanner;
public class BasicInput
public static void mainString args
Scanner scnr new ScannerSystemin;
int userInt ;
double userDouble ;
char userChar;
String userString;
System.out.printlnEnter integer:";
userInt scnrnextInt;
System.out.printlnEnter double:";
userDouble scnrnextDouble;
System.out.printlnEnter character:";
userChar scnrnextcharAt;
System.out.printlnEnter string:";
userString scnrnext;
System.out.printlnuserInt userDouble userChar userString;
System.out.printlnuserString userChar userDouble userInt;
int castedInt int userDouble;
System.out.printlnCasting userDouble to an integer is castedInt;
scnrclose;
Here's the error that I am receiving:
Output differs. See highlights below.
Special character legend
Input
z
Howdy
:Compare output
Your output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
Howd
Expected output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
:Compare output
Output differs. See highlights below.
Special character legend
Input
A
Plethora
Your output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
A Plethora
Plet
Expected output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
A Plethora
:Compare output
Output differs. See highlights below.
Special character legend
Input
z
Howdy
Your output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
Howdy z
Cast
Expected output starts with
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
Howdy z
:Compare output
Output differs. See highlights below.
Special character legend
Input
z
Howdy
Your output
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
Howdy z
Casting to an integer is
Expected output
Enter integer:
Enter double:
Enter character:
Enter string:
z Howdy
Howdy z
cast to an integer is
:Compare output
Output differs. See highlights below.
Special character legend
Input
m
Bye
Your output
Enter integer:
Enter double:
Enter character:
Enter string:
m Bye
Bye m
Casting to an integer is
Expected output
Enter integer:
Enter double:
Enter character:
Enter string:
m Bye
Bye m
cast to an integer is
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started