Advertisement
Guest User

ss

a guest
Nov 27th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package ss;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4. public class ss {
  5.  
  6.        
  7.         public static void main(String[] args) {
  8.                 // TODO Auto-genera;ted method stub
  9. int[][] tab = new int [5][5];
  10. int x,n;
  11. x=0;
  12. n=0;
  13.  
  14. Scanner odczyt = new Scanner(System.in);
  15. System.out.print("Podaj liczbe:");
  16. x = odczyt.nextInt();
  17. Random losuj = new Random();
  18.  
  19.  
  20. for(int i=0;i<5;i++) {
  21.                 for(int j=0;j<5;j++){
  22.     tab[i][j]= losuj.nextInt(50);
  23.                 }  
  24. }
  25.  
  26.  
  27. for(int i=0;i<5;i++){
  28.         for(int j=0;j<5;j++)
  29.         {
  30.           if(x==tab[i][j])
  31.           {
  32.                  n++;
  33.          }
  34. }
  35. }
  36.  
  37.  
  38. System.out.println("Wylosowana tablica:");
  39. for(int i=0;i<5;i++){
  40.          for(int j=0;j<5;j++){
  41.              
  42.          
  43.     System.out.print(" ["+tab[i][j]+"]");
  44.             if( j==4){
  45.                 System.out.println(" ["+tab[i][j]+"]");
  46.             }
  47.          }
  48. }
  49.  
  50.  
  51. System.out.println("");
  52. System.out.println("Trafiles "+n);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement