Created
August 16, 2017 05:10
-
-
Save fazd/2d7f164f64a4a609c6eacbc621f333be to your computer and use it in GitHub Desktop.
This file contains 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
package alpaca; | |
public class Alpaca { | |
public static String elec(char str){ | |
if(str=='A') | |
return "AL"; | |
if(str=='L') | |
return "PACA"; | |
if(str=='P') | |
return "CP"; | |
if(str=='C') | |
return "PC"; | |
return ""; | |
} | |
public static String formation(String str){ | |
String total=""; | |
for(int i=0; i<str.length(); i++){ | |
total=total+elec(str.charAt(i)); | |
} | |
return total; | |
} | |
public static int cont(String str){ | |
int tot=0; | |
for(int i=0; i<str.length()-5; i++){ | |
if(str.substring(i, i+6).equals("ALPACA")){ | |
tot++; | |
} | |
} | |
return tot; | |
} | |
public static void main(String[] args) { | |
String A= "A"; | |
int tot; | |
for (int i=1; i<=10; i++){ | |
A=formation(A); | |
tot=cont(A); | |
System.out.println("I="+i); | |
System.out.println("TOT="+tot); | |
//System.out.println(A); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment