Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- /**
- *
- * @author DOM
- */
- public class Main {
- /**
- * @param args the command line arguments
- */
- public static void main (String[] args)throws IOException {
- // TODO code application logic here
- System.out.println("Tablica:");
- int [] tablica=new int[20];
- Random generator=new Random();
- for (int i=0; i<tablica.length; i++){
- tablica[i]=generator.nextInt(10);
- System.out.print("[" +(tablica[i])+ "]");
- }
- System.out.println("\nPodaj liczbę całkowitą z przedziału od 1 do 9:");
- int a = 0;
- BufferedReader odczyt = new BufferedReader(new InputStreamReader(System.in));
- String temp = odczyt.readLine();
- try {
- a = Integer.parseInt(temp);
- if (a>9) System.out.println("Podana liczba jest za duża (max. 9)");
- if (a<1) System.out.println("Podana liczba jest za mała (min. 1)");
- System.exit(1);
- }
- catch (NumberFormatException ex) {
- System.out.println("Podany ciąg znaków nie jest liczbą!");
- System.exit(1);
- }
- int liczba=0;
- for (int i=0; i<tablica.length; i++){
- if (tablica[i]==a){
- liczba++;
- }
- }
- System.out.println("["+liczba+"]");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement