Program to display any digit from 0-9 using "7 segment display"

In this program, we have to display number in 7 segment display form. User have to  input any digit from 0 to 9 and after that it will display number in 7 segment display format.

For example-

If input digit is "0" then it will display following output
 _ 
|  |
|_|

If entered digit is "4" then output will be
|_|
    |

If entered digit is "9" then output will be
 _ 
|_|
  _|


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;
    }
  }
}
OUTPUT




Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative