Por que isso funciona

Por que o java 5 aceita colocar tantos “;” no meio do código ?
Olhe e teste o exemplo abaixo.

public class Operadores { public static void main(String... args) { byte b1 = 5;;;;; ; ; ; ; ;; ; byte b2 = 10;;;;;; ; ; ; ; ; ; ;;;;;;; ;;;;;;;;;;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; System.out.println(b1 +" - "+ b2); } }
Este código compila perfeitamente e printa “5 - 10”.

Qualquer versão do java aceita isso. Na verdade o que você está fazendo é enchendo de comandos vazios. Cada vírgula é um marcador de fim de comando, então se você deixar vazio entre uma vírgula e outra, então o que acontece é que você está colocando um comando vazio que simplesmente não faz nada.

hum…
eu ja tinha visto isso antes, mas não me lembrava porque o java aceita este tipo de código.
valeu pela ajuda.

Qual a finalidade colocar esse monde de ponto-e-virgulas?!
Vc queria testar algo?! :?:

é pra ter certeza que não vai dar erro de compilação… hehehehe…

:idea:

huahuahauhua… gostei da resposta Kabah! :slight_smile:

Agora, por que isto funciona? Diga o que este programa faz(Copie o código seguinte para um arquivo “Exercicio.java”, compile-o, e rode-o com “java -cp . Exercicio”).

\u0069\u006D\u0070\u006F\u0072\u0074 \u006A\u0061\u0076\u0061\u002E\u0075\u0074\u0069\u006C\u002E\u002A\u003B
\u0063\u006C\u0061\u0073\u0073 \u0045\u0078\u0065\u0072\u0063\u0069\u0063\u0069\u006F \u007B
\u0009\u0070\u0075\u0062\u006C\u0069\u0063 \u0073\u0074\u0061\u0074\u0069\u0063 \u0076\u006F\u0069\u0064 \u006D\u0061\u0069\u006E\u0028\u0053\u0074\u0072\u0069\u006E\u0067\u005B\u005D \u0061\u0072\u0067\u0073\u0029 \u007B
\u0009\u0009\u0053\u0063\u0061\u006E\u006E\u0065\u0072 \u0073\u0063\u0061\u006E \u003D \u006E\u0065\u0077 \u0053\u0063\u0061\u006E\u006E\u0065\u0072 \u0028\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u0069\u006E\u0029\u003B
\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074 \u0028\u0022\u004E\u006F\u006D\u0065 \u0064\u0061 \u0070\u0072\u0069\u006D\u0065\u0069\u0072\u0061 \u0070\u0065\u0073\u0073\u006F\u0061\u003A \u0022\u0029\u003B
\u0009\u0009\u0053\u0074\u0072\u0069\u006E\u0067 \u006E\u006F\u006D\u0065\u0031 \u003D \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u004C\u0069\u006E\u0065\u0028\u0029\u003B
\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074 \u0028\u0022\u0050\u0065\u0073\u006F \u0065\u006D \u006B\u0067\u003A \u0022\u0029\u003B
\u0009\u0009\u0069\u006E\u0074 \u0070\u0065\u0073\u006F\u0031 \u003D \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u0049\u006E\u0074\u0028\u0029\u003B \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u004C\u0069\u006E\u0065\u0028\u0029\u003B
\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074 \u0028\u0022\u004E\u006F\u006D\u0065 \u0064\u0061 \u0073\u0065\u0067\u0075\u006E\u0064\u0061 \u0070\u0065\u0073\u0073\u006F\u0061\u003A \u0022\u0029\u003B
\u0009\u0009\u0053\u0074\u0072\u0069\u006E\u0067 \u006E\u006F\u006D\u0065\u0032 \u003D \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u004C\u0069\u006E\u0065\u0028\u0029\u003B
\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074 \u0028\u0022\u0050\u0065\u0073\u006F \u0065\u006D \u006B\u0067\u003A \u0022\u0029\u003B
\u0009\u0009\u0069\u006E\u0074 \u0070\u0065\u0073\u006F\u0032 \u003D \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u0049\u006E\u0074\u0028\u0029\u003B \u0073\u0063\u0061\u006E\u002E\u006E\u0065\u0078\u0074\u004C\u0069\u006E\u0065\u0028\u0029\u003B
\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u006C\u006E \u0028\u0022\u004F \u0069\u006E\u0064\u0069\u0076\u0069\u0064\u0075\u006F \u006D\u0061\u0069\u0073 \u0070\u0065\u0073\u0061\u0064\u006F \u0065\u0068\u003A \u0022\u0029\u003B
\u0009\u0009\u0069\u0066 \u0028\u0070\u0065\u0073\u006F\u0031 \u003E \u0070\u0065\u0073\u006F\u0032\u0029 \u007B
\u0009\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u0066 \u0028\u0022\u0025\u0073\u002C \u0063\u006F\u006D \u0025\u0064 \u006B\u0067\u0025\u006E\u0022\u002C \u006E\u006F\u006D\u0065\u0031\u002C \u0070\u0065\u0073\u006F\u0031\u0029\u003B
\u0009\u0009\u007D \u0065\u006C\u0073\u0065 \u0069\u0066 \u0028\u0070\u0065\u0073\u006F\u0031 \u003C \u0070\u0065\u0073\u006F\u0032\u0029 \u007B
\u0009\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u0066 \u0028\u0022\u0025\u0073\u002C \u0063\u006F\u006D \u0025\u0064 \u006B\u0067\u0025\u006E\u0022\u002C \u006E\u006F\u006D\u0065\u0032\u002C \u0070\u0065\u0073\u006F\u0032\u0029\u003B
\u0009\u0009\u007D \u0065\u006C\u0073\u0065 \u007B
\u0009\u0009\u0009\u0053\u0079\u0073\u0074\u0065\u006D\u002E\u006F\u0075\u0074\u002E\u0070\u0072\u0069\u006E\u0074\u0066 \u0028\u0022\u0025\u0073 \u0065 \u0025\u0073 \u0074\u0065\u006D \u006F \u006D\u0065\u0073\u006D\u006F \u0070\u0065\u0073\u006F \u002D \u0025\u0064 \u006B\u0067\u0025\u006E\u0022\u002C \u006E\u006F\u006D\u0065\u0031\u002C \u006E\u006F\u006D\u0065\u0032\u002C \u0070\u0065\u0073\u006F\u0031\u0029\u003B
\u0009\u0009\u007D
\u0009\u007D
\u007D

o kaabah respondeu corretamente. huahuahuahuah
falowwwwwwwwww.