A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 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