0

So when I use .nextLine on my code it clumps up the rest of the input codes after that. When I get rid of the line part of .nextLine it won't take an answer with space. The end result would clump up Place enter your street address and please enter your city.

import java.util.Scanner;

public class InformationNew
{

   public static void main(String [] args) 
   {   
         //create Scanner class
      Scanner console = new Scanner(System.in);

         //declare varibles
      String firstName, lastName, city, state, upper, lower, streetAdd;
      char firstInt, lastInt;
      int age, size, indexOfSpace;
      double wage;

         //inputs
      System.out.print("Please enter your first name: ");
      firstName = console.next();

      System.out.print("Please enter your last name: ");
      lastName = console.next();

      System.out.print("Please enter your street address: ");
      streetAdd = console.nextLine();

      System.out.print("Please enter your city: ");
      city = console.next();

      System.out.print("Please enter your state: ");
      state = console.next();

      System.out.print("Please enter your age: ");
      age = console.nextInt();

      System.out.print("Please enter your annual income: ");
      wage = console.nextDouble();

      System.out.println();

         //manipulate strings
      indexOfSpace = streetAdd.indexOf( " " );

      firstInt = firstName.charAt(0);

      lastInt = lastName.charAt(0);

      size = city.length();



         //outputs
      System.out.println("User Information: ");
      System.out.println("***************** ");

      System.out.println("Your Name: " + lastName + ", " + firstName);
      System.out.println("Your Initials: " + firstInt + lastInt);
      System.out.println("Characters in city name: " + size);
      System.out.println("User Location (uppercase): " + city.toUpperCase() + ", 
      " + state.toUpperCase());
      System.out.println("User Location (lowercase): " + city.toLowerCase() + ", 
      `enter code here`" + state.toLowerCase());
      System.out.println("Your age: " + age);
      System.out.printf("Your annual income: $%.2f", wage);


   }//end main


}//end class

Result

Please enter your first name: Jon
Please enter your last name: Doe
Please enter your street address: Please enter your city:

0 Answers0