Posted By

mille9393 on 08/20/18


Tagged


Versions (?)

1232


 / Published in: Java
 

123

  1. import java.util.*;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. public class lasdo {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10. Random random = new Random(10);
  11. List<Integer> talArray = new ArrayList<>();
  12.  
  13. //shufflar array
  14. for (int i = 1; i <= 10; i++) {
  15. talArray.add(i);
  16.  
  17. }
  18. Collections.shuffle(talArray);
  19. //end shufflad array
  20.  
  21.  
  22. System.out.println("Skriv in ditt tal");
  23. int chosenNum = scanner.nextInt();
  24. //i<=talArray.size();)
  25.  
  26. for (int i = talArray.size(); i > 0; ) {
  27. //shufflar arrayen igen
  28. Collections.shuffle(talArray);
  29. int correctAsnwer = chosenNum * talArray.indexOf(i);
  30.  
  31. System.out.println("What is " + chosenNum + " * " + talArray.indexOf(i) + "?");
  32. int answer = scanner.nextInt();
  33.  
  34. if (chosenNum * talArray.indexOf(i) == answer) {
  35. i--; //minska loop med 1
  36. System.out.println(correctAsnwer + " är rätt. Snyggt!");
  37. } else {
  38. System.out.println("Fel svar.");
  39. }
  40. }
  41. }
  42. }

Report this snippet  

You need to login to post a comment.