classHobbits{Stringnome;// init var nome with value null publicstaticvoidmain(String[]args){// The size of this array is 3 and the arrays in Java begin at index 0Hobbits[]h=newHobbits[3];intz=-1;// init var z at -1 // this loop continue while value of z is less than 2while(z<2){z=z+1;// the firt time z=-1+1 , Attention d'ont forget that when z=1 so z++ = 2h[z]=newHobbits();h[z].nome="bilbo";// the variable nome is put to value "bilbo" when z=0if(z==1){h[z].nome="frodo";// the variable nome is put to value "frodo" when z=1}if(z==2){h[z].nome="sam";// the variable nome is put to value "sam" when z=2}System.out.print(h[z].nome+" eh ");System.out.println("Um bom nome para um Hobbit!");}}}/* OUTPUT Result : bilbo eh Um bom nome para um Hobbit!frodo eh Um bom nome para um Hobbit!sam eh Um bom nome para um Hobbit!*/
robson_oliveira
Bom dia…
[REMOVIDO LINK PARA CONTEÚDO PAGO]
davidbuzatto
O Use a Cabeça é gratuido? :shock:
J
JoedsonSCosta
Obrigado, me ajudou bastante…
J
JoedsonSCosta
Vou seguir as dicas… vlw galera
J
JoedsonSCosta
Boa noite,
Por favor, alguém pode me dizer qual é o erro desse código, pois tenho quase certeza que está correto, mas não roda?!!
class Exercicio{
public static void main(String[] args){
for (long fatorial=1, n=1; n<30; n++){
fatorial *=n;
System.out.println(fatorial);
}
}
}
davidbuzatto
JoedsonSCosta:
Boa noite,
Por favor, alguém pode me dizer qual é o erro desse código, pois tenho quase certeza que está correto, mas não roda?!!
class Exercicio{
public static void main(String[] args){
for (long fatorial=1, n=1; n<30; n++){
fatorial *=n;
System.out.println(fatorial);
}
}
}
Evite esse tipo de construção do for.
Teste assim:
int n = 10;
long fatorial = 1;
for ( int i = 1; i <= n; i++ ) {
fatorial *= i;
}
System.out.println(fatorial);