Created
April 9, 2014 17:42
-
-
Save ahmetilhann/10295973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void lookandsay(String str) | |
{ | |
int[] intArray = new int[str.length()+1]; //str boyutu kadar array oluşturulur | |
//Bir sonraki eleman ile kontrol ettiğimiz için bottan 1 fazla olarak oluşturuyoruz. | |
for(int i=0;i<str.length();i++) //str de bulunan her karakte int'e çevrilerek diziye kelenir | |
intArray[i]=Character.getNumericValue(str.charAt(i)); | |
int x=1; | |
String result=""; | |
for(int i=0;i<str.length();i++) | |
{ | |
if(intArray[i]==intArray[i+1]) //Bir sonraki eleman ile kendisi eşitse sayisi 1 artırılır | |
{x++;} | |
else //eşit olmayınca sonuca sayisi ve kendisi eklenir. | |
{ | |
result=result+Integer.toString(x)+Integer.toString(intArray[i]); | |
x=1; | |
} | |
} | |
System.out.println(result); //sonuç | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jasper-client