I am just wondering whether is it possible to display number in digital format.
In this we are accepting number from console.
For example:
123 should be display in following format, and in one line.
_ _
| _| _|
| |_ _|
I tried using switch case but not got appropriate method
"arg" is char array;
char c;
for(i=0;i<3;i++)
{
c=arg[i];
switch(char)
{
case '1' : System.out.println("|");
System.out.println("|");
break;
case '2' : System.out.println("-");
System.out.println(" "+"|");
System.out.println("-");
System.out.println("|");
System.out.println("-");
break;
same for all digit
}
}
I know this is not a correct solution to display.
Is it any alternative for this using java.
EDIT
Updated code which is suggested by Joe. It works.
/**
* @author Amit
*/
public class DigitalDisplay {
/**
* @param args
*/
public static void main(String[] args) {
String [][] num=new String[4][3];
num[0][0]="|-|";
num[0][1]="| |";
num[0][2]="|_|";
num[1][0]=" |";
num[1][1]=" |";
num[1][2]=" |";
num[2][0]=" -|";
num[2][1]=" _|";
num[2][2]=" |_";
num[3][0]=" -|";
num[3][1]=" _|";
num[3][2]=" _|";
int[] input = {2,1,3};
for (int line = 0; line < 3; line++)
{
for (int inputI=0; inputI < input.length; inputI++)
{
int value = input[inputI];
System.out.print(num[value][line]);
System.out.print(" ");
}
System.out.println();
}
}
}
**OUTPUT**
-| | -|
_| | _|
|_ | _|
@Joe: Thanks.
If you have more than one character, you need to scan across each line, building it up.
All of the following is pseudocode, but I am sure you can translate it into Java. You will need to create a grid and ensure that each digit has the same width and height.
1 – Set up your initial data for each number. You could do this as a 2d array (dimension 1: digit, dimension 2: line) For example:
2 – For each line that makes up the character, scan across each digit in your input and write the appropriate string. This will build up the characters line by line.
Fine, here’s the java: