Last active
February 22, 2016 22:38
-
-
Save Viacheslav77/892151efcfd8e3b33678 to your computer and use it in GitHub Desktop.
Написать класс, который умеет хранить в себе массив любых типов данных (int, long etc.). Реализовать метод, который возвращает любой элемент массива по индексу.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package AnyTapeArray; | |
| public class AnyTapeArray <E> { | |
| private E [] arr; | |
| public E getArrIndex(int i){ | |
| return arr[i] ; | |
| } | |
| public void setArr( E [] arr){ | |
| this.arr = arr; | |
| } | |
| public int getLength(){ | |
| return arr.length ; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String Hello World ! | |
| Integer 1 2 3 4 5 6 7 8 | |
| Double 1.2 1.5 6.7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package AnyTapeArray; | |
| /*Написать класс, который умеет хранить в себе массив любых типов | |
| данных (int, long etc.). Реализовать метод, который возвращает | |
| любой элемент массива по индексу.*/ | |
| public class MyClass { | |
| public static <E> void sid (String s, E [] arr){ | |
| E [] a = arr; | |
| AnyTapeArray <E> sid = new AnyTapeArray <E> (); | |
| sid.setArr(a); | |
| System.out.print(s + " "); | |
| for(int i = 0; i< sid.getLength(); i++) | |
| System.out.print(sid.getArrIndex(i)+" "); | |
| System.out.println(); | |
| } | |
| public static void main(String [] args){ | |
| String [] s = {"Hello", "World","!"}; | |
| sid("String" , s); | |
| Integer [] intr = { 1,2,3,4,5,6,7,8}; | |
| sid("Integer" , intr); | |
| Double [] ad = {1.2,1.5,6.7}; | |
| sid("Double" , ad); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment