Java开发工程师面试题1
时间2019-1-2 地点上海
package service;
import java.text.SimpleDateFormat;
import java.util.Date;
public class test1 {
public static void main(String[] args){
String time = new SimpleDateFormat("HH:mm").format(new Date());
String hour = time.substring(0,2);
String minute = time.substring(3,5);
System.out.println(hour+minute);
gethourn1(hour);
gethourn2(hour);
getMin1(minute);
getMin2(minute);
display(gethourn1(hour)); System.out.print(" "); System.out.println();
display(gethourn2(hour)); System.out.println();
System.out.println();
System.out.println(" . . ");
System.out.println("");
display(getMin1(minute)); System.out.println("");
display(getMin2(minute));
// String times[] = new String[5];
// times[0] = display(gethourn1(hour));
// displaytime("1"); displaytime("1");
// displaytime("2");
}
public static String gethourn1(String hour){
String hourn1 = hour.substring(0,1);
return hourn1;
}
public static String gethourn2(String hour){
String hourn2 = hour.substring(1,2);
return hourn2;
}
public static String getMin1(String min){
String min1 = min.substring(0,1);
return min1;
}
public static String getMin2(String min){
String min2 = min.substring(1,2);
return min2;
}
public static void displayColLine(){
System.out.print("| ");
}
public static void displayRowLine(){
System.out.println(" -- ");
}
public static void display(String number){
if ("0".equals(number)){
displayRowLine();
displayColLine(); displayColLine(); System.out.println("");
displayColLine(); displayColLine(); System.out.println("");
displayRowLine();
}
if ("1".equals(number)){
displayColLine();System.out.println("");displayColLine(); System.out.println();
}
if ("2".equals(number)){
displayRowLine();
System.out.print(" ");displayColLine(); System.out.println("");
displayRowLine();
displayColLine(); System.out.println("");
displayRowLine();
}
if ("3".equals(number)){
displayRowLine();
System.out.print(" "); displayColLine(); System.out.println("");
displayRowLine();
System.out.print(" "); displayColLine(); System.out.println("");
displayRowLine();
}
if ("4".equals(number)){
displayRowLine();
displayColLine(); displayColLine(); System.out.println("");
displayRowLine();
System.out.print(" "); displayColLine(); System.out.println("");
}
if ("5".equals(number)){
displayRowLine();
displayColLine(); System.out.println("");
displayRowLine();
System.out.print(" "); displayColLine(); System.out.println("");
displayRowLine();
}
if ("6".equals(number)){
displayColLine(); System.out.println("");
displayRowLine();
System.out.print(""); displayColLine();System.out.print(""); displayColLine(); System.out.println("");
displayRowLine();
}
if ("7".equals(number)){
displayRowLine(); System.out.print(" ");
displayColLine();System.out.println(""); System.out.print(" ");
displayColLine();
}
if ("8".equals(number)){
displayRowLine();
displayColLine(); displayColLine(); System.out.println("");
displayRowLine();
displayColLine(); displayColLine(); System.out.println("");
displayRowLine();
}
if ("9".equals(number)){
displayRowLine();
displayColLine(); displayColLine(); System.out.println("");
displayRowLine(); System.out.print(" ");
displayColLine();
}
}
}
packageservice;
importjava.text.SimpleDateFormat;
importjava.util.Date;
publicclasstest2{
publicstaticString[][]num0=newString[][]{{"","-",""},{"|","","|"},{"","",""},{"|","","|"},{"","-",""}};
publicstaticString[][]num1=newString[][]{{"","",""},{"","","|"},{"","",""},{"","","|"},{"","",""}};
publicstaticString[][]num2=newString[][]{{"","-",""},{"","","|"},{"","-",""},{"|","",""},{"","-",""}};
publicstaticString[][]num3=newString[][]{{"","-",""},{"","","|"},{"","-",""},{"","","|"},{"","-",""}};
publicstaticString[][]num4=newString[][]{{"","",""},{"|","","|"},{"","-",""},{"","","|"},{"","",""}};
publicstaticString[][]num5=newString[][]{{"","-",""},{"|","",""},{"","-",""},{"","","|"},{"","-",""}};
publicstaticString[][]num6=newString[][]{{"","-",""},{"|","",""},{"","-",""},{"|","","|"},{"","-",""}};
publicstaticString[][]num7=newString[][]{{"","-",""},{"","","|"},{"","",""},{"","","|"},{"","",""}};
publicstaticString[][]num8=newString[][]{{"","-",""},{"|","","|"},{"","-",""},{"|","","|"},{"","-",""}};
publicstaticString[][]num9=newString[][]{{"","-",""},{"|","","|"},{"","-",""},{"","","|"},{"","-",""}};
publicstaticString[][]option=newString[][]{{"","",""},{"","●",""},{"","",""},{"","●",""},{"","",""}};
publicstaticString[][][]numAll=newString[][][]{num0,num1,num2,num3,num4,num5,num6,num7,num8,num9};
publicstaticSimpleDateFormatsdf=newSimpleDateFormat("HH:mm");
publicstaticvoidmain(String[]args){
print();
}
publicstaticvoidprint(){
String[][][]newStr=getDateArray();
for(inti=0;i<5;i++){
for(intk=0;k<newStr.length;k++){
for(intj=0;j<3;j++){
System.out.print(newStr[k][i][j]);
}
System.out.print("");
}
System.out.println();
}
}
publicstaticString[][][]getDateArray(){
String[][][]dateArray=newString[5][][];
StringdateStr=sdf.format(newDate());
char[]dateChars=dateStr.toCharArray();
for(inti=0;i<dateChars.length;i++){
switch(dateChars[i]){
case':':
dateArray[i]=option;
break;
default:
dateArray[i]=numAll[Integer.valueOf(String.valueOf(dateChars[i]))];
break;
}
}
returndateArray;
}
}