Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package esercizio3.iterable;
- import java.util.Iterator;
- import java.util.NoSuchElementException;
- public class IterableString {
- public String testo;
- public IterableString(String s)
- {
- this.testo = s;
- }
- public Iterator<Character> iterator()
- {
- return new MYit();
- }
- private class MYit implements Iterator<Character>
- {
- int pos = 0;
- @Override
- public boolean hasNext() {
- return pos >= 0 || pos < IterableString.this.testo.length();
- }
- @Override
- public void remove() {
- if (!hasNext()) throw new IllegalStateException("pos minore");
- Character toBeRemoved = IterableString.this.testo.charAt(pos);
- String temp = new String();
- for (int i = 0; i < IterableString.this.testo.length(); i++)
- {
- if (pos != i)
- temp = temp + IterableString.this.testo.charAt(i);
- }
- IterableString.this.testo = temp;
- }
- @Override
- public Character next() {
- if(!hasNext())
- {
- throw new NoSuchElementException("Has no next element");
- }
- Character ritorno = IterableString.this.testo.charAt(pos);
- pos++;
- return ritorno;
- }
- }
- }
- ---------------------------------------------------------------------------------------------------------------------------------------
- package esercizio1;
- import java.util.Arrays;
- public class Esercizio1 {
- public void ordina(int[][] m)
- {
- if ( m == null || m.length == 0) throw new IllegalArgumentException(new String("fuck you"));
- int[] buffer = new int[m.length * m[0].length];
- int buffIter = -1;
- for (int i = 0; i < m.length; i++)
- {
- for (int j = 0; j < m[i].length; j++)
- {
- buffer[++buffIter] = m[i][j];
- }
- }
- Arrays.sort(buffer);
- System.out.println(Arrays.toString(buffer));
- buffIter = 0;
- for (int i = 0; i < m.length; i++) {
- for (int j = 0; j < m[0].length; j++) {
- m[i][j] = buffer[buffIter++];
- }
- }
- System.out.println(Arrays.deepToString(m));
- }
- public static void main(String args[])
- {
- Esercizio1 es = new Esercizio1();
- //int[][] in = {{2,54,6},{3,67,24},{43,68,43},{90,74,76}};
- int[][] in = null;
- es.ordina(in);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement