Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with Zybooks Activity 2.1.9.1. For some reason Zybooks is very picky

ID: 3734329 • Letter: I

Question

I need help with Zybooks Activity 2.1.9.1. For some reason Zybooks is very picky in the output according to the screenshot and need to know if it's perfect and what needs changed. I asked my professor and the output looks like this. https://i.imgur.com/UXc0clJ.png The string "Howdy has a space and I cannot figure out why and it will give me an F if the code is not perfect format and everything. Please check over the code. Thanks.

Here is my 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 userChar = '-'; // FIXME Define char and string variables similarly
       String userString = "";
      
       System.out.println("Enter Integer:");
       userInt = scnr.nextInt();
      
       // FIXME (1): Finish reading other items into variables, then output the four values on a single line separated by a space
      
       System.out.println("Enter Double:");
       userDouble = scnr.nextDouble();
       System.out.println("Enter Character:");
       userChar = scnr.next().charAt(0);
       System.out.println("Enter String:");
       userString = scnr.nextLine();
       System.out.println(userInt + " " + userDouble + " " + userChar + " " + userString);
      
      // FIXME (2): Output the four values in reverse
      System.out.println(userString + " " + userChar + " " + userDouble + " " + userInt);
     
      
      // FIXME (3): Cast the double to an integer, and output that integer
      
       System.out.println(userDouble + " " + "cast to an integer is " + (int)userDouble);
      return;
   }
}

Explanation / Answer

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 userChar = '-'; // FIXME Define char and string variables similarly
String userString = "";
  
System.out.println("Enter String:");
userString = scnr.nextLine();//Read the input data upto new line including spaces

System.out.println("Enter Integer:");
userInt = scnr.nextInt();
  
// FIXME (1): Finish reading other items into variables, then output the four values on a single line separated by a space
  
System.out.println("Enter Double:");
userDouble = scnr.nextDouble();
System.out.println("Enter Character:");
userChar = scnr.next().trim().charAt(0);

  

System.out.println(userString);
System.out.println(userInt + " " + userDouble + " " + userChar + " " + userString);
  
// FIXME (2): Output the four values in reverse
System.out.println(userString + " " + userChar + " " + userDouble + " " + userInt);

  
// FIXME (3): Cast the double to an integer, and output that integer
  
System.out.println(userDouble + " " + "cast to an integer is " + (int)userDouble);
return;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote