I was trying to make a program which reads your temperature, gives you a feedback as to how good it is, above, under or inbetween the average bodytemperature. After this I want the program to ask the user whether he/she wants to do another reading, by input. For this I use a switch-statement. It almost works fine: the user input y, the program loops again and all is jolly good. However, when the user input n, the program still restarts? Can anyone help me as to why this is happening?
The code:
import java.util.*;
class Uke2Ekstra17{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
boolean lokke=true;
while(lokke=true){
System.out.println("Vennligst oppgi temperaturen din, så skal du få vite om du ligger over, under eller innenfor gjennomsnittstemperaturen! Skriv her: ");
double temp=input.nextDouble();
if(temp<36.5){
System.out.println("Du ligger under gjennomsnittet med " + (36.5-temp) + " grader.");
}else if(temp>36.5 && temp<37.5){
System.out.println("Du ligger innenfor gjennomsnittstemperaturen.");
}else{
System.out.println("Du ligger over gjennomsnittet med " + (temp-37.5) + " grader.");
}
System.out.println("Vil du gjøre en ny maaling? y/n: ");
char svar=input.next().charAt(0);
switch(svar){
case 'y':
lokke=true;
break;
case 'n':
lokke=false;
break;
}
}
}
}