I am very new to Java (and generally programming). I am sure that the solution to my problem is very simple, but I just can not figure it out. The code below is a small part of my program. But it still compiles and still has the same problem.
Here is the code ::
import java.util.Scanner;
public class Practice{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String command = "";
double d;
double t;
double s;
System.out.println("Hello, I am the Physics Calculator!!");
while (!command.equals("end")){
System.out.print("What would you like to calculate?: ");
command = input.nextLine();
System.out.println();
if (command.equals("speed")){
System.out.print("What is the distance in meters?: ");
d = input.nextDouble();
System.out.print("What is the time is seconds?: ");
t = input.nextDouble();
s = d / t;
System.out.println("The Speed is "+ s +" m/s");
System.out.println();
}
}
}
}
The first line of code inside the while loop:
System.out.println("What would you like to calculate?: ");
So far so good. When I run the program, it prints: * What would you like to calculate ?: * And then the program will continue as expected.
The problem is that the program reaches the end of the while loop and returns to the beginning of the while loop. he will print:
What would you like to calculate ?: What do you want to calculate ?:
I just can't understand why he prints it twice.
, ( - , - ):
{
, !!
?:
?: 50
?: 50
1,0 /
?:
?:
} End
"" . " ".
, , !
!