Skip to content

Instantly share code, notes, and snippets.

@mattiaferigutti
Last active April 4, 2017 16:26
Show Gist options
  • Save mattiaferigutti/8e6416c29d0b7880de0a95604b52a55e to your computer and use it in GitHub Desktop.
Save mattiaferigutti/8e6416c29d0b7880de0a95604b52a55e to your computer and use it in GitHub Desktop.
package Prova;
/**
* Created by Mattia on 05/03/2017.
*/
public class Estrazione
{
private String stringa;
public Estrazione(String stringa) {
this.stringa = stringa;
}
public void EstrazioneDoppie()
{
int a, i;
char prima, seconda;
for (i=0, a=1; i<stringa.length(); i++, a++)
{
try
{
prima = stringa.charAt(i);
seconda = stringa.charAt(a);
if(prima == seconda)
{
System.out.println("ci sono doppie: " + prima + seconda);
}
}
catch(StringIndexOutOfBoundsException e){}
//System.out.println("i: " + i + "\na: " + a + "\n");
}
}
}
package Prova;
/**
* Created by Mattia on 05/03/2017.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProgEstrazione
{
public static void main(String[] args)
{
System.out.print ("Inserisci parola: ");
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader myInput = new BufferedReader(reader);
String str= new String();
try {
str = myInput.readLine();
} catch (IOException e) {
System.out.println ("Si è verificato un errore: " + e);
System.exit(-1);
}
Estrazione estr = new Estrazione(str);
estr.EstrazioneDoppie();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment