- #1
Itisjurrr
- 1
- 0
Hows it going MHB. This is my first post and probably will not be my last. I am not going to come here just asking for answers, but to look for help in my coding adventure. I am currently enrolled into a entry level coding course that kind of just jumps right into things and does give some help with books, but not very useful at times. The problem that I am currently stuck on is this part
(1) 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 2 points).
Enter integer: 99
Enter double: 3.77
Enter character: z
Enter string: Howdy
99 3.77 z Howdy
The output of my code is showing me this
Enter interger: 99
Enter double: 3.77
Enter character: Z
Enter string: Z Howdy
99 3.77 Z Z Howdy
That is what I need to accomplish in my code. I am some how getting an extra z when I put in my user inputs.
Thanks,
Jerry
(1) 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 2 points).
Enter integer: 99
Enter double: 3.77
Enter character: z
Enter string: Howdy
99 3.77 z Howdy
The output of my code is showing me this
Enter interger: 99
Enter double: 3.77
Enter character: Z
Enter string: Z Howdy
99 3.77 Z Z Howdy
Code:
import java.util.Scanner;
public class BasicInput {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int userInt = 0;
double userDouble = 0.0;
char letterZ = '0';
String firstWord = "";
// FIXME Define char and string variables similarly
userInt = scnr.nextInt();
userDouble = scnr.nextDouble();
letterZ = 'Z';
firstWord = scnr.nextLine();
System.out.println("Enter interger: " + userInt);
System.out.println("Enter double: " + userDouble);
System.out.println("Enter character: " + letterZ);
System.out.println("Enter string: " + firstWord);
System.out.print(userInt);
System.out.print(" ");
System.out.print(userDouble);
System.out.print(" ");
System.out.print(letterZ);
System.out.print(firstWord);
// FIXME (1): Finish reading other items into variables, then output the four values on a single line separated by a space
// FIXME (2): Output the four values in reverse
// FIXME (3): Cast the double to an integer, and output that integer
return;
}
}
That is what I need to accomplish in my code. I am some how getting an extra z when I put in my user inputs.
Thanks,
Jerry