-1

I was working on a project and I figured out that when I read more than one String from one obj of Scanner it may skip one and it's solved when I make more than 1 obj but why does that happen I mean what it's the cycle that processor go through !! in this code variable z is skipped from reading and the program end so any one could help me figuring this out please and thanks in advance

    package calculater;
    import java.util.Scanner;
    public class Calculater {

        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            String x = scan.nextLine();
            double y = scan.nextDouble();
            String z = scan.nextLine();
        }

    }

1 Answers1

0

You could try to write

double y = Double.parseDouble(scan.nextLine());

instead of

double y = scan.nextDouble();
Marce
  • 480
  • 1
  • 6
  • 8