java - Wrong Quiz result -


this output of program

i able till this result doing program below

import java.util.scanner;  public class alittlequiz {      public static void main(string[] args) {          // declaring varibles          string quizstart;         int quizans1, quizans2, quizans3;          scanner input = new scanner(system.in);          system.out.println("are ready quiz? (y / n)");         quizstart = input.next();          system.out.println("okay, here comes!");          // quiz answer 1          system.out.println("\nwhat capital of alaska? \n1) melbourne\n2) anchorage\n3) juneau");         quizans1 = input.nextint();          if (quizans1 == 3) {             system.out.println("that's right");         } else {             system.out.println("your answer wrong, sorry!");         }          // quiz answer 2          system.out.println("q2) can store value ''cat'' in variable of type int? \n1) yes \n2) no");         quizans2 = input.nextint();          if (quizans2 == 1) {             system.out.println("sorry, ''cat'' string. ints can store numbers.");         } else if (quizans2 == 2) {             system.out.println("correct!");         }          // quiz answer 3          system.out.println("what result of 9+6/3? \n1) 5\n2) 11 \n3) 15/3");         quizans3 = input.nextint();         if (quizans3 == 2) {             system.out.println("that's correct!");         } else {             system.out.println("");         }          // if (quizans == 3 && quizans == ) {          // }      }  } 

but how can program part?

"overall, got 2 out of 3 correct. playing!"

declare variable int marks , increment 1 inside if\else block(which made correct answer). , @ end print

system.out.println("overall, got" +marks+" out of 3 correct. playing!");

assuming no of question fixed( 3 )

        string quizstart;         int quizans1, quizans2, quizans3;         int marks=0;          scanner input = new scanner(system.in);          system.out.println("are ready quiz? (y / n)");         quizstart = input.next();          system.out.println("okay, here comes!");          // quiz answer 1          system.out.println("\nwhat capital of alaska? \n1) melbourne\n2) anchorage\n3) juneau");         quizans1 = input.nextint();          if (quizans1 == 3) {             system.out.println("that's right");             ++marks;         } else {             system.out.println("your answer wrong, sorry!");         }          // quiz answer 2          system.out.println("q2) can store value ''cat'' in variable of type int? \n1) yes \n2) no");         quizans2 = input.nextint();          if (quizans2 == 1) {             system.out.println("sorry, ''cat'' string. ints can store numbers.");         } else if (quizans2 == 2) {             system.out.println("correct!");             ++marks;         }          // quiz answer 3          system.out.println("what result of 9+6/3? \n1) 5\n2) 11 \n3) 15/3");         quizans3 = input.nextint();         if (quizans3 == 2) {             system.out.println("that's correct!");             ++marks;         } else {             system.out.println("");         }         system.out.println("overall, got " +marks+" out of 3 correct. playing!"); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -