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
|_|
|
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
_
|_|
_|
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