Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // Scanner import
- public class worksheet2 { // program begins
- public static void main(String[] args) {
- //Question taken from CAPE Pure Mathematics June 2018 Paper 1, #16
- Scanner input = new Scanner (System.in); // Scanner declaration
- // variable declaration
- int answer;
- final int ans1 = 4, ans2 = 15, ans3 = -2, ans4 = 0;
- System.out.println("A circle is defined as (x+2)^2 + y^2 = 4. The gradient of the normal to the circle at (0,0) is: ? Your options: 4, 15, 0, -2 or 999 to exit.");
- answer = input.nextInt();
- while (answer != 999) { //while loop being used as a continuous loop, and it can be exited when 999 is entered.
- //if statements being used to compare the answer the user entered with the ones that have been initialised within program
- if(answer == ans1) {
- System.out.println("4 is the incorrect answer, please try again.");
- }
- if(answer == ans2) {
- System.out.println("15 is the incorrect answer, please try again.");
- }
- if(answer == ans3) {
- System.out.println("-2 is the incorrect answer, please try again.");
- }
- if(answer == ans4) {
- System.out.println("0 is the correct answer. Congratulations!");
- }
- //updating variable within loop
- System.out.println("A circle is defined as (x+2)^2 + y^2 = 4. The gradient of the normal to the circle at (0,0) is: ? Your options: 4, 15, 0, -2 or 999 to exit.");
- answer = input.nextInt();
- } //while loop ends
- System.out.println("Thank you for answering."); //goodbye statement, will appear when 999 is entered
- }
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement