我只是想知道是否可以用数字格式显示数字。 在这我们正在接受控制台的号码。如何打印像7段显示器的多位数字
例如:
123 should be display in following format, and in one line.
_ _
| _| _|
| |_ _|
我使用开关壳体尝试,但没有得到适当的方法
"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的任何替代方案。
编辑 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**
-| | -|
_| | _|
|_ | _|
@Joe:谢谢。
有什么不对您的解决方案?使用“_”而不是“ - ”,它应该工作 – Hachi
“没有合适的方法” - 更具描述性。问题是什么? –
我认为你需要退一步 - 你想在哪里显示这些数字(上下文是什么),以及为什么在这种特殊的形式?您的需求是否可以通过使用不同的字体来满足? –