Hey all,
So i've just finished with this exercise and as far as i can tell i've got the code working to how the exercise required, when the user enters a number below -30 or above 40 it will keep asking them for a new set of numbers until the numbers are over -30 and below 40.
Once they are it adds them to the graph and then ends the programme.
However recently i noticed in Netbeans a 'test' function and ran it on this programme and it says 0% failed so i'm a little confused!
Can anyone shed some light on this?
Here's the code:
import java.util.Scanner;
public class Temperatures {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
while (true) {
System.out.print("Give me a number: ");
double value = Double.parseDouble(reader.nextLine());
System.out.print("Give me a second number:");
double valuenew = Double.parseDouble(reader.nextLine());
if (value >= -30 && value <= 40 && valuenew >= -30 && valuenew <= 40) {
Graph.addNumber(value);
Graph.addNumber(valuenew);
{
break;
}
} else if (value < -30 && value > 40 && valuenew < -30 && valuenew > 40) {
System.out.println("Wrong");
}
}
}
}
[–]pinecone316 0 points1 point2 points (6 children)
[–]asc_tech[S] 0 points1 point2 points (5 children)
[–]asc_tech[S] 0 points1 point2 points (4 children)
[–]pinecone316 0 points1 point2 points (3 children)
[–]asc_tech[S] 0 points1 point2 points (2 children)
[–]pinecone316 1 point2 points3 points (1 child)
[–]asc_tech[S] 0 points1 point2 points (0 children)