Created
March 21, 2017 17:12
-
-
Save mattiaferigutti/cd7cd88719a6af1f99d287610513c3f0 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
public class MiaStringa | |
{ | |
String stringa; | |
public MiaStringa(String stringa) | |
{ | |
this.stringa = stringa; | |
} | |
public void selezionaCarattere() | |
{ | |
int lunghezza = stringa.length(); | |
if ((lunghezza % 2) == 0) | |
{ | |
int prima = (lunghezza/2) -1; | |
char tPosPrima = stringa.charAt(prima); | |
int seconda = (lunghezza/2); | |
char tPosSeconda = stringa.charAt(seconda); | |
System.out.println("prima " + tPosPrima + " seconda " + tPosSeconda); | |
}else | |
{ | |
int t = (lunghezza/2); | |
char tPos = stringa.charAt(t); | |
System.out.println("la stringa " + tPos); | |
} | |
} | |
} |
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
public class StringaMain | |
{ | |
public static void main(String[] args) | |
{ | |
MiaStringa stringa = new MiaStringa("buongiorno"); | |
stringa.selezionaCarattere(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment