{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Common1ans

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

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern