Magna Concursos
2404482 Ano: 2010
Disciplina: TI - Desenvolvimento de Sistemas
Banca: CESPE / CEBRASPE
Orgão: CEF
Provas:
Apresenta-se abaixo o código completo de uma classe escrita na linguagem Java. Esse código é plenamente compilável e executável.
1 public class Main {
2 protected String contentType = null;
3 public static String characterEncoding = “ISO-8859-1”;
4 protected boolean charsetSet = false;
5 public static void main(String[] args) {
6 new Main() .setContentType(args[0]);
7 }
8 public void setContentType(String type) {
9 int semicolonIndex = -1;
10 if (type == null) {this.contentType = null; return;}
11 boolean hasCharset = false;
12 int len = type.length();
13 int index = type.index0f(‘;’);
14 while (index != -1) {
15 semicolonIndex = index; index++;
16 while (index < len && Character.isSpace(type.charAt(index))) {index++;}
17 if (index + 8 < len
18 && type.charAt(index) == ‘c’ && type.charAt(index + 1) == ‘h’
19 && type.charAt(index + 2) ==‘a’ && type.charAt(index + 3) == ‘r’
20 && type.charAt(index + 4) ==‘s’ && type.charAt(index + 5) == ‘e’
21 && type.charAt(index + 6) ==‘t’ && type.charAt(index + 7) == ‘=’) {
22 hasCharset = true; break;
23 }
24 index = type.index0f(‘;’, index);
25 }
26 if (!hasCharset) { this.contentType = type; return; }
27 this.contentType = type.substring(0, semicolonIndex);
28 String tail = type.substring(index + 8);
29 int nextParam = tail.index0f(‘;’);
30 String charsetValue = null;
31 if (nextParam != -1) {
32 this.contentType += tail.substring(nextParam);
33 charsetValue = tail.substring(0, nextParam);
34 } else { charsetValue = tail; }
35 if (charsetValue != null && charsetValue.length() > 0) {
36 charsetSet = true;
37 charsetValue = charsetValue.replace(‘”’,’’);
38 this. characterEncoding = charsetValue.trim();
39 }
40 }
41 }
Acerca do comportamento que o código mostrado apresentará quando estiver sendo executado, assinale a opção correta.
 

Provas

Questão presente nas seguintes provas

Técnico Bancário - TI

60 Questões