Oracle Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
1
of 1 vote

public class SevenSegmentDisplay
{
    // Class private variable:
    private short segments = 9;
    private short[][] digits;
    private short[][] map = {{0, 1, 0, 1, 0, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 1, 0, 0, 1}, 
                             {0, 1, 0, 0, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 1, 1, 0, 1, 1}, 
                             {0, 0, 0, 1, 1, 1, 0, 0, 1}, {0, 1, 0, 1, 1, 0, 0, 1, 1},
                             {0, 1, 0, 1, 1, 0, 1, 1, 1}, {0, 1, 0, 1, 0, 1, 0, 0, 1}, 
                             {0, 1, 0, 1, 1, 1, 1, 1, 1}, {0, 1, 0, 1, 1, 1, 0, 1, 1}};
    // Constructor:
    public SevenSegmentDisplay(String numberStr)
    {
        digits = new short[numberStr.length()][segments];
        for (int i = 0; i < numberStr.length(); i++)
        {
            int number = Character.getNumericValue(numberStr.charAt(i));
            digits[i] = map[number];
        }
        display(digits);
    }
    
    // display Method:
    private void display(short[][] digits)
    {
        String symbol;
        int segment = 0;
        boolean line1 = true;
        while (segment <= 7)
        {    
            for (int i = 0; i <= (digits.length - 1); i++)
            {
                for (int j = segment; j <= (segment + 2); j++)
                {
                    if (line1) symbol = "_"; else if (j == (segment + 1)) symbol = "_"; else symbol = "|";
                    if (digits[i][j] == 0) System.out.print(" "); else System.out.print(symbol);
                }
            }
            line1 = false;
            System.out.println("");
            segment = segment + 3;
        }
    }
    
    // Client code:
    public static void main (String[] args)
    {
        SevenSegmentDisplay test = new SevenSegmentDisplay("35464565413958");
    }
}

- MahmoudMheisen91 March 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

see my implementation @codepad.org/rxXAzFAJ

- Dirt_Diver May 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take 3*3 matrix with values like _, |, _ etc. just hide the values based on input number.

- Kiran September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static Map<Integer, char[][]> map = null;
	static {
	char[][] zero = new char[3][3];
		zero[0][0]=' ';zero[0][1]='_';zero[0][2]=' ';
		zero[1][0]='|';zero[1][1]=' ';zero[1][2]='|';
		zero[2][0]='|';zero[2][1]='_';zero[2][2]='|';
	char[][] one = new char[3][3];
		one[0][0]=' ';one[0][1]=' ';one[0][2]=' ';
		one[1][0]=' ';one[1][1]='|';one[1][2]=' ';
		one[2][0]=' ';one[2][1]='|';one[2][2]=' ';
	char[][] two = new char[3][3];
		two[0][0]=' ';two[0][1]='_';two[0][2]=' ';
		two[1][0]=' ';two[1][1]='_';two[1][2]='|';
		two[2][0]='|';two[2][1]='_';two[2][2]=' ';
		map = new HashMap<Integer, char[][]>();
		map.put(0, zero);map.put(1, one);map.put(2, two);
	}
	public static void main(String[] args) {
		StringBuffer sb = new StringBuffer();
		int[] toPrint = {0,1,2};
		for(int i=0; i<=2; i++){
			for(int j =0; j <toPrint.length; j++){
				char[][] arr = map.get(toPrint[j]);
				for(int k=0; k<=2;k++){
					sb.append(arr[i][k]);
				}				
			}	sb.append('\n');		
		}
		System.out.println(sb.toString());
	}

- Ashis Kumar March 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Wow there is no Computer Engineer in this form? its just 7 segment display. have a number of 7 bits which toggles the respected segment when it is 1 or 0. that is it!

- Solx November 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if displaying it is on a hardware 7 segment display. (not computer screen)

- Anonymous November 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SevenSegmentDisplay
{
    // Class private variable:
    private short segments = 9;
    private short[][] digits;
    private short[][] map = {{0, 1, 0, 1, 0, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 1, 0, 0, 1}, 
                             {0, 1, 0, 0, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 1, 1, 0, 1, 1}, 
                             {0, 0, 0, 1, 1, 1, 0, 0, 1}, {0, 1, 0, 1, 1, 0, 0, 1, 1},
                             {0, 1, 0, 1, 1, 0, 1, 1, 1}, {0, 1, 0, 1, 0, 1, 0, 0, 1}, 
                             {0, 1, 0, 1, 1, 1, 1, 1, 1}, {0, 1, 0, 1, 1, 1, 0, 1, 1}};
    // Constructor:
    public SevenSegmentDisplay(String numberStr)
    {
        digits = new short[numberStr.length()][segments];
        for (int i = 0; i < numberStr.length(); i++)
        {
            int number = Character.getNumericValue(numberStr.charAt(i));
            digits[i] = map[number];
        }
        display(digits);
    }
    
    // display Method:
    private void display(short[][] digits)
    {
        String symbol;
        int segment = 0;
        boolean line1 = true;
        while (segment <= 7)
        {    
            for (int i = 0; i <= (digits.length - 1); i++)
            {
                for (int j = segment; j <= (segment + 2); j++)
                {
                    if (line1) symbol = "_"; else if (j == (segment + 1)) symbol = "_"; else symbol = "|";
                    if (digits[i][j] == 0) System.out.print(" "); else System.out.print(symbol);
                }
            }
            line1 = false;
            System.out.println("");
            segment = segment + 3;
        }
    }
    
    // Client code:
    public static void main (String[] args)
    {
        SevenSegmentDisplay test = new SevenSegmentDisplay("35464565465456125468712128165482610520078078011012413958");
    }

}

- MahmoudMheisen91 March 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

See my implementation and the sample output @codepad.org/DShK94iy

- ashot madatyan May 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good idea.

A slightly different idea I was thinking of is to do the following:
+ Provide numbers to each part of the display i.e.
1 => _
2 => |
3 => ...
+ For each number, set the "number" combination to display.

This is not as easy to code as your alternative, but will save some space by avoiding duplicate strings. For example, have
one number to represent "\0\0\0\0\0".

- Anonymous May 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why do you need "\0\0\0\0\0"

- Anonymous May 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can safely ignore the last lines containing NULL chars, they were meant for other stuff, which I had no time to implement(character unerlining, etc). Moreover, we can reduce the width of the chars printed by using only 4 clumns instead of 5.
Sample output is below (hope the edit box will not screw it :))

_       _   _       _   _   _   _   _
| |  |   _|  _| |_| |_  |_    | |_| |_|
|_|  |  |_   _|   |  _| |_|   | |_|  _|

- ashot madatyan May 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

could you please explain the logic

- Anonymous May 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can divide the String into characters. For each character we give corresponding mappings like the above format. It is not the easy way?

- varma May 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We can divide the String into characters. For each character we give corresponding mappings like the above format. It is not the easy way?

- varma May 29, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More