Ho risolto da solo cosi:
codice:import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Chiamata { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Inserire il nome del pkm: "); String testocap = scan.nextLine(); String testi = testocap.substring(0, 1).toLowerCase() + testocap.substring(1); String pikachu = "Nome: pikachu \nPokedex: 025 \nSpecie: Topo \nEvoluzione: Pichu\n"; String squirtle = "Nome: squirtle \nPokedex: 02 \nSpecie: Scoiattolo \nEvoluzione: Wartholt\\Blastoise\n"; String charmander = "Nome: charmander \nPokedex: 04 \nSpecie: Lucertola \nEvoluzione: Charmeleon\\Charizard\n"; String[] array = new String [3]; array[0] = pikachu; array[1] = squirtle; array[2] = charmander; for (int i = 0; i < array.length; i++){ boolean found = array[i].indexOf (testi) != -1; Pattern pattern = Pattern.compile("[a-z]+"); Matcher matcher = pattern.matcher(testi); if (found && matcher.matches() == false) { System.out.println("Sicuro?"); break; }else{ if(found && matcher.matches()){ System.out.println(array[i]); } } } } }

Rispondi quotando