Program to display Digits in 7-Segment Style Using Java
Display Digits in 7-Segment Style Using Java
Ever wondered how digital clocks or calculators display numbers? They often use seven-segment displays—a simple arrangement of 7 LEDs to represent numbers from 0 to 9. In this post, we'll create a Java program that simulates the same effect on your console screen!
๐ก What is a 7-Segment Display?
A 7-segment display is made up of seven LEDs (labeled a through g) that can be turned on or off to create numerical digits. Here's a visual representation:
Each digit is formed by turning on a combination of these segments.
The Seven segment display have 7 segments as shown below:

PROGRAM
import java.util.*;
public class DigitToSevenDisplay
{
public static void main(String[] args) throws Exception
{
Scanner inr = new Scanner(System.in);
int n = inr.nextInt();
// Add the necessary code in the below space
switch(n)
{
case 0:
System.out.println(" _ \n| | \n|_|");
break;
case 1:
System.out.println(" \n |\n |");
break;
case 2:
System.out.println(" _ \n _|\n|_ ");
break;
case 3:
System.out.println(" _ \n _|\n _|");
break;
case 4:
System.out.println(" \n|_|\n |");
break;
case 5:
System.out.println(" _ \n|_ \n _|");
break;
case 6:
System.out.println(" _ \n|_ \n|_|");
break;
case 7:
System.out.println(" _ \n |\n |");
break;
case 8:
System.out.println(" _ \n|_|\n|_|");
break;
case 9:
System.out.println(" _ \n|_|\n _|");
break;
}
}
}
Comments
Post a Comment