Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Look-and-say-sequence/Java/look-and-say-sequence-1.java
Normal file
18
Task/Look-and-say-sequence/Java/look-and-say-sequence-1.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
public static String lookandsay(String number){
|
||||
StringBuilder result= new StringBuilder();
|
||||
|
||||
char repeat= number.charAt(0);
|
||||
number= number.substring(1) + " ";
|
||||
int times= 1;
|
||||
|
||||
for(char actual: number.toCharArray()){
|
||||
if(actual != repeat){
|
||||
result.append(times + "" + repeat);
|
||||
times= 1;
|
||||
repeat= actual;
|
||||
}else{
|
||||
times+= 1;
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
public static void main(String[] args){
|
||||
String num = "1";
|
||||
|
||||
for (int i=1;i<=10;i++) {
|
||||
System.out.println(num);
|
||||
num = lookandsay(num);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue