37 lines
778 B
Java
37 lines
778 B
Java
package com.cool.week414;
|
|
|
|
/**
|
|
* Created with IntelliJ IDEA.
|
|
*
|
|
* @Author: Cool
|
|
* @Date: 2024/09/08/11:28
|
|
* ProblemNumber
|
|
*/
|
|
public class Problem1 {
|
|
public String convertDateToBinary(String date) {
|
|
String[] dates=date.split("-");
|
|
String res="";
|
|
for(int i=0;i<dates.length;i++){
|
|
int dateInt=Integer.parseInt(dates[i]);
|
|
res+=trans(dateInt);
|
|
if(i!=dates.length-1){
|
|
res+="-";
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
private String trans(int date){
|
|
if(date==0){
|
|
return "0";
|
|
}
|
|
String res="";
|
|
while(date!=0){
|
|
int num=date%2;
|
|
date=date/2;
|
|
res=String.valueOf(num)+res;
|
|
}
|
|
return res;
|
|
}
|
|
}
|