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 zad4tablice;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author Shineko
- */
- public class Zad4tablice {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- Random r = new Random();
- int wymiar;
- do
- {
- //System.out.println(wymiar);
- wymiar = (r.nextInt(51)) + 50;
- }
- while(wymiar%4 != 0);
- //System.out.println(wymiar);
- int tab [][] = new int [wymiar][wymiar];
- System.out.println("Podaj początek zakresu losowań:");
- System.out.print("> ");
- int a = in.nextInt();
- System.out.println("Podaj koniec zakresu losowań:");
- System.out.print("> ");
- int b = in.nextInt();
- if(b <= a)
- {
- do
- {
- System.out.println("Nieprawdiłowa wartość. Koniec musi być większy od początku.");
- System.out.println("Podaj koniec zakresu losowań:");
- System.out.print("> ");
- b = in.nextInt();
- }
- while( b <= a);
- }
- System.out.println("A: " + a + ", B: " + b);
- int minus = wymiar / 4;
- int plus = 3 * minus;
- for(int i = 0; i < wymiar; i++)
- {
- for(int j = 0; j < wymiar; j++)
- {
- if( j != i)
- {
- tab [i][j] = (r.nextInt(b - a + 1) + b);
- }
- else
- {
- Boolean c = r.nextBoolean();
- if( c == true)
- {
- plus--;
- if(plus < 0)
- {
- tab [i][j] = -1;
- }
- else
- {
- tab [i][j] = 1;
- }
- }
- else
- {
- minus--;
- if(minus < 0)
- {
- tab[i][j] = 1;
- }
- else
- {
- tab[i][j] = -1;
- }
- }
- }
- }
- }
- int liczKom = 0;
- for(int i = 0; i < wymiar; i++)
- {
- for(int j = 0; j < wymiar; j++)
- {
- if( tab [i][j] < i * j)
- {
- liczKom++;
- }
- }
- }
- System.out.println("Liczba komórek, których wartość jest mniejsza od iloczynu indeksu wiersza i kolumny tych komórek wynosi: " + liczKom);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement