Friday, October 18, 2019

Java programming and written exercises Essay Example | Topics and Well Written Essays - 750 words

Java programming and written exercises - Essay Example 2. Assume a class Square that implements the interface Comparable. You are required to implement the method compareTo so that squares are compared according to their sides. Part of the Java code has been provided as below. Please complete the code inside the compareTo() method. 4. Write a Java code segment that uses the LinkedList myList and the String array strArr. Store the elements from the array in the linked list. Use an iterator to scan the list and output the elements of strings, whose length is greater than 5. String[] strArr = {"Java", "Programming", "if", "array", "LinkedList", "queue", "iterator"}; LinkedList myList = new LinkedList(); private int i; for(i=0;i 5) { Insert(string strArr[i], LinkedListIterator p); } } public voidinsert(stringx,LinkedListIteratorp) { if(p!=null&&p.current!=null) p.current.next=newListNode(x,p.current.next); } 5. Trace the call f(16) to the following method. Show how you work out the result. public static int f(int n) { int result=0; if (n

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.