Posted By

mille9393 on 08/20/18


Tagged


Versions (?)

sweclockers


 / Published in: Java
 

sweclockers

  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.  
  25. for (int i = 1; i<talArray.size(); i++){
  26. int correctAsnwer = chosenNum * talArray.indexOf(i);
  27.  
  28. System.out.println("What is " + chosenNum + " * " + talArray.indexOf(i) + "?");
  29. int answer = scanner.nextInt();
  30.  
  31. if(chosenNum * talArray.indexOf(i) == answer){
  32. System.out.println(correctAsnwer + " är rätt. Snyggt!");
  33. } else {
  34. System.out.println("Fel svar.");
  35. }
  36. }
  37.  
  38.  
  39. }
  40.  
  41.  
  42. }

Report this snippet  

You need to login to post a comment.