Urubin
Nuovo Utente
- Messaggi
- 15
- Reazioni
- 5
- Punteggio
- 23
Ciao a tutti! Oramai è da un ora che sto cercando di capire come mai questo oggetto (Integer)
che ho passato alla mia funzione non cambia valore anche nel main.
Ringrazio in anticipo tutti per il supporto!
che ho passato alla mia funzione non cambia valore anche nel main.
Ringrazio in anticipo tutti per il supporto!
Codice:
//FUNZIONE CHE CONTA GLI SPAZI PRESENTI IN OGNI STRINGA DELLE 2 SEQUENZE
public static int contaspazi(String[] array, Integer contaparole)
{
int conta=0;
for(int i=0; i<3; i++)
{
if(array[i].charAt(0) >= 'a' && array[i].charAt(0) <= 'z')
contaparole++;
for(int j=0; j<array[i].length()-1; j++)
{
if(array[i].charAt(j) == ' ')
{
conta++;
if(array[i].charAt(j+1) >= 'a' && array[i].charAt(j+1) <= 'z')
contaparole++;
}
}
}
return conta;
}
public static void main(String[] args)
{
Integer contaparole = 0;
String[] a= new String[3];
String[] a1=new String[3];
Scanner input = new Scanner(System.in);
//INPUT SEQUENZE
for(int i=0; i<3; i++)
{
System.out.println("inserire la stringa del primo array: ");
a[i]=input.nextLine();
}
for(int i=0; i<3; i++)
{
System.out.println("inserire la stringa del secondo array: ");
a1[i]=input.nextLine();
}
System.out.println("Gli spazi presenti nelle tre stringhe della PRIMA SEQUENZA sono: " + contaspazi(a, contaparole));
System.out.println("MAIN: " + contaparole);
System.out.println("Gli spazi presenti nelle tre stringhe della PRIMA SEQUENZA sono: " + contaspazi(a1, contaparole));
System.out.println("MAIN: " + contaparole);
}