Isogram J 1
INDEX
-----------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Isogramma</title>
</head>
<body>
<form action="prova" method="post">
<div align="center">
<h1>Verifica Isogramma</h1>
<label >Inserisci la frase</label>
<input type="text" name="frase" style="width:400px">
<input type="submit" name="Verifica" value="Verifica">
</div>
<div align="center">
<% if(request.getAttribute("risposta")!=null) {%>
<p><%= request.getAttribute("risposta") %>
<% } %>
</div>
</form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------
CLASSE MODEL
package it.cefi.models;
import java.util.Arrays;
public class Isogramma {
private String parola;
public Isogramma() {
}
public boolean controlloIsogramma(String stringa) {
stringa = stringa.toLowerCase();
int lunghezza = stringa.length();
char arr[] = stringa.toCharArray();
Arrays.sort(arr);
for (int i = 0; i < lunghezza - 1; i++) {
if (arr[i] == arr[i + 1])
return false;
}
return true;
}
public String getParola() {
return parola;
}
public void setParola(String parola) {
this.parola = parola;
}
}
Commenti
Posta un commento