我只是想知道是否可以以数字格式显示数字。在此我们接受来自控制台的号码。
例如:
123 should be display in following format, and in one line.
_ _
| _| _|
| |_ _|
我尝试使用 switch case 但没有得到合适的方法
"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
}
}
我知道这不是正确的显示解决方案。
是否可以使用 java.lang.
编辑 Joe 建议的更新代码。有用。
/**
* @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**
-| | -|
_| | _|
|_ | _|
@乔:谢谢。