Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Java Scanning input issue

Charles R. EarleyCharles R. Earley Member Posts: 2

Hello,

I have a problem, when I execute this program it won't allow me to enter the string input when I have String myStr = scan.nextLine(); BUT if I change to String myStr = scan.next(); it only reads on word then stop, how do I fix this?

`import java.util.Scanner;
public class myPlayGround {

public static void main(String args[]) {


myMethod(); 

}
public static void myMethod() {
    int i = 9;
    double d = 1.0;
    String string = "Rick";

    Scanner scan = new Scanner(System.in);

    System.out.println("enter a number");
    int integer = scan.nextInt();


    System.out.println("Enter a double");
    double doub = scan.nextDouble();

    System.out.println("Enter a string");
    String myStr = scan.nextLine();


    System.out.println(i + integer);
    System.out.println(d + doub);
    System.out.println(string + " " +  myStr);
}

}`

Sign In or Register to comment.