Common1ans

Common1ans - CS 114 Exam 1 Name 1 Section Write a recursive method void hex(int n that takes an integer parameter and prints the number in

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2009.

Page1 / 5

Common1ans - CS 114 Exam 1 Name 1 Section Write a recursive method void hex(int n that takes an integer parameter and prints the number in

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online