import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String characters;
Scanner scan = new Scanner(System.in);
boolean quit = false;
do {
System.out.println("USD to SEK converter");
System.out.println("Enter 'quit' to exit the program");
System.out.print("Enter USD amount: ");
if (scan.hasNextDouble()) {
double usd = scan.nextDouble();
double sek = usd * 11.2;
System.out.println(sek);
}else if(scan.hasNextLine()) {
characters = scan.nextLine();
System.out.println(characters);
if (characters.equals("quit")) {
quit = true;
}
}
}while (!quit);
}
}
I am making a USD to SEK converter and when I input 1 +, I first get the conversion of 1 USD to SEK and then get +. Why is the program first checking 1 and then + and not both at the same time? If I input 1+, I get 1+. No conversion of 1. If I enter 1+2 I get 1+2 and when I enter 1 + 2 I first get the conversion on 1 USD to SEK and then + 2.