{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Common1ans - CS 114 Exam 1 Name 1 Section Write a recursive...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 114 Exam 1 Name___________________________________ Section_______________________ 1. Write a recursive method void hex(int n) that takes an integer parameter and prints the number in hexadecimal. You can assume that the input is greater than zero. public void hex(int n) { if(n > 0) { hex(n/16); if(n%16 < 10) System.out.print(n%16); else System.out.print((char)(n%16 -10 + 'A'); } } public void hex(int n) { if(n > 0) { hex(n/16); switch(n%16) { case 10: System.out.print('A'); break; case 11: System.out.print('B'); break; case 12: System.out.print('C'); break; case 13: System.out.print('D'); break; case 14: System.out.print('E'); break; case 15: System.out.print('F'); break; default: System.out.print(n%16); } } } Page 1 of 5
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The following problems use the classes below. The methods in the List class are described but the implementations are not given. public class Link { public Object data; public Link next; public Link(Object d, Link n){data = d; next = n;} } public class List { private Link head; // reference to head of linked list private Link tail; // reference to tail of linked list public List(){head = tail = null;} public void insertHead(Object data){//insert at head of list}
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern