DEV Community

loading...
Cover image for Day 20: Seven-segment display

Day 20: Seven-segment display

mattryanmtl profile image Matt Ryan ・1 min read

A seven-segment display is a form of electronic display device for displaying decimal numerals.

Alt Text

public class Display {
    public static void main(String[] args) {
        Display pd = new Display();
            pd.setAssoc("5647");
    }

    public void setAssoc(String inputn) {

    String[][] nums = {
            { "+--+ ", "   + ", "+--+ ", "+--+ ", "+  + ", "+--+ ","+--+ ", "+--+ ", "+--+ ", "+--+ " },
            { "|  | ", "   | ", "   | ", "   | ", "|  | ", "|    ","   | ", "   | ", "|  | ", "|  | " },
            { "|  | ", "   | ", "   | ", "   | ", "|  | ", "|    ","   | ", "   | ", "|  | ", "|  | " },
            { "+  + ", "   + ", "+--+ ", "+--+ ", "+--+ ", "+--+ ","+--+ ", "   + ", "+--+ ", "+--+ " },
            { "|  | ", "   | ", "|    ", "   | ", "   | ", "   | ","|  | ", "   | ", "|  | ", "   | " },
            { "|  | ", "   | ", "|    ", "   | ", "   | ", "   | ","|  | ", "   | ", "|  | ", "   | " },
            { "+--+ ", "   + ", "+--+ ", "+--+ ", "   | ", "+--+ ","+--+ ", "   + ", "+--+ ", "+--+ " } };

              for (int i = 0; i < 7; i++) {
                  for (int j = 0; j < inputn.length(); j++) {
                           int index = inputn.charAt(j) - 48;
                           System.out.print(nums[i][index]);
                  }
               System.out.println();
              }
      }
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app