Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hoa2mathapp_echaure;
- import java.util.Scanner;
- import java.util.Random;
- public class HOA2MathApp_Echaure {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner myObj = new Scanner(System.in);
- char operator = myObj.next().charAt(0);
- int i = 0, a, user;
- Random rand = new Random();
- while (i < 1) {
- System.out.println("~~~~~Welcome to Math Challenge!~~~~~\n");
- System.out.println(" To Start Please Choose The Operator That You Like");
- System.out.println(" | + | | - | | * | | / |");
- switch (operator){
- case '+':
- System.out.println("Yoou have chosen Addition!");
- while (i < 5){
- int r1 = rand.nextInt(50);
- int r2 = rand.nextInt(50);
- System.out.println(r1 + " + " + r2);
- a = r1 + r2;
- user = myObj.nextInt();
- if (user == a){
- System.out.println("Correct!");
- i++;
- }
- else {
- System.out.println("Wrong Answer!");
- System.out.println(" The Answer is " + a);
- }
- }
- break;
- case '-':
- System.out.println("You have chosen Subtraction!");
- while (i < 5){
- int r1 = rand.nextInt(50);
- int r2 = rand.nextInt(50);
- System.out.println(r1 + " - " + r2);
- a = r1 - r2;
- user = myObj.nextInt();
- if (user == a){
- System.out.println("Correct!");
- i++;
- }
- else {
- System.out.println("Wrong Answer!");
- System.out.println(" The Answer is " + a);
- }
- }
- break;
- case '*':
- System.out.println("You have chosen Multiplication!");
- while (i < 5){
- int r1 = rand.nextInt(50);
- int r2 = rand.nextInt(50);
- System.out.println(r1 + " * " + r2);
- a = r1 * r2;
- user = myObj.nextInt();
- if (user == a){
- System.out.println("Correct!");
- i++;
- }
- else {
- System.out.println("Wrong Answer!");
- System.out.println(" The Answer is " + a);
- }
- }
- break;
- case '/':
- System.out.println("You have chosen Division!");
- while (i < 5){
- int r1 = rand.nextInt(50);
- int r2 = rand.nextInt(50);
- System.out.println(r1 + " / " + r2);
- a = r1 / r2;
- user = myObj.nextInt();
- if (user == a){
- System.out.println("Correct!");
- i++;
- }
- else {
- System.out.println("Wrong Answer!");
- System.out.println(" The Answer is " + a);
- }
- }
- break;
- default :
- System.out.println("\nPlease input a valid operator!");
- }
- System.out.println("Would you like to try again with a different operator?");
- System.out.println("Press 1 for YES and 2 for NO");
- char reply;
- c = myObj.nextInt();
- if (c == 2){
- i++;
- }
- else {
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement