Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ListsArrays;
- import java.util.Scanner;
- public class ProstiSlozeni {
- /*public static SLL<Integer> slozheni (Array<Integer> niza)
- {
- SLL<Integer> slozheni = new SLL<Integer>();
- for(int i=0; i<niza.getLength(); i++)
- {
- slozheni.insertLast(niza.get(i));
- }
- return slozheni;
- }*/
- public static boolean prost(Integer a)
- {
- for(int i=2; i<a; i++)
- {
- if(a % i== 0)
- {
- return false;
- }
- }
- return true;
- }
- public static SLL<Integer> prosti (Array<Integer> niza)
- {
- SLL<Integer> prosti = new SLL<Integer>();
- for(int i=0; i<niza.getLength(); i++)
- {
- if(prost(niza.get(i)))
- {
- prosti.insertLast(niza.get(i));
- }
- }
- return prosti;
- }
- public static SLL<Integer> slozheni (Array<Integer> niza)
- {
- SLL<Integer> slozheni = new SLL<Integer>();
- for(int i=0; i<niza.getLength(); i++)
- {
- if(!prost(niza.get(i)))
- {
- slozheni.insertLast(niza.get(i));
- }
- }
- return slozheni;
- }
- public static void main(String[] args)
- {
- Scanner s = new Scanner(System.in);
- System.out.println("Vnesi n: ");
- int n = s.nextInt();
- Array<Integer> niza = new Array<Integer>(n);
- System.out.println("Vnesi niza: ");
- for(int i=0; i<niza.getLength(); i++)
- {
- niza.set(i, s.nextInt());
- }
- SLL<Integer> prosti = prosti(niza);
- SLL<Integer> slozheni = slozheni(niza);
- System.out.println("Prosti: " + prosti);
- System.out.println("Slozheni: " + slozheni);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement