Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zadanie17;
- import java.util.Scanner;
- public class mass {
- public static int getUnEven(String st) {
- int count = 0;
- for(int i=0; i<st.length(); i++) {
- if (Character.isDigit(st.charAt(i)))
- if (st.charAt(i) % 2 != 0)
- count++;
- }
- return count;
- }
- public static void swap(String[] st, int n) {
- int[] C = new int[n];
- for(int i=0; i<n; i++)
- C[i] = getUnEven(st[i]);
- int maxIndex = 0;
- int max = C[maxIndex];
- int minIndex = n-1;
- int min = C[minIndex];
- for(int i=0; i<n; i++) {
- if (C[i]>max) {
- maxIndex = i;
- max = C[maxIndex];
- }
- if (C[i]<min) {
- minIndex = i;
- min = C[minIndex];
- }
- }
- String temp = st[maxIndex];
- st[maxIndex] = st[minIndex];
- st[minIndex] = temp;
- }
- public static void printMas(String[] st) {
- for(int i=0; i<st.length; i++) {
- System.out.print(st[i] + " ");
- }
- System.out.println();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner in=new Scanner(System.in);
- int n = in.nextInt();
- String[] s = new String[n];
- for(int i=0; i<s.length; i++) {
- s[i]=in.next();
- }
- printMas(s);
- swap(s,n);
- printMas(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement