Advertisement
lukag99

Zavrsni-Grupa1

Jan 12th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package nikola;
  7.  
  8. import java.util.Arrays;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author Luka
  14.  */
  15. public class grupa1 {
  16.    
  17.     public static void main(String[] args) {
  18.         grupa1 a = new grupa1();
  19.         a.popuniNiz();
  20.         a.popuniDrugiNiz();
  21.     }
  22.    
  23.     int niz1[] = new int[10];
  24.     int niz2[] = new int[100];
  25.    
  26.     public void popuniNiz(){
  27.        
  28.         System.out.println("Unesite broj preko tastature");
  29.         Scanner input = new Scanner(System.in);
  30.        
  31.         for(int i=0;i<niz1.length;i++){
  32.             int broj = input.nextInt();
  33.             if(broj %2 != 0){
  34.                 niz1[i] = broj;
  35.             }else{
  36.                 System.out.println("Niste uneli neparan broj");
  37.                 int broj2 = input.nextInt();
  38.                 niz1[i] = broj2;
  39.             }    
  40.         }    
  41.         System.out.println(Arrays.toString(niz1));
  42.         int brojac = 0;
  43.         for(int i = niz1.length-1; i>=0; i--){
  44.             if(brojac++ %2 != 0){
  45.                 continue;
  46.             }
  47.             System.out.println("Element"+i+": "+niz1[i]);
  48.         }
  49.     }
  50.    
  51.     public void popuniDrugiNiz(){
  52.         for(int i=0;i<niz2.length;i++){
  53.             niz2[i]=niz1[i % niz1.length]-1;
  54.         }
  55.         System.out.println(Arrays.toString(niz2));
  56.         int brojac = 0;
  57.         for(int i=niz2.length-1; i>=0; i--){
  58.             if(brojac++ %2 != 0){
  59.                 continue;
  60.             }
  61.             System.out.println("Element"+i+": "+niz2[i]);
  62.         }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement