Java Notes

Best Practice

Don't include too many arguments (hard to change)

// want to read and print reversely 5 lines
String[] lines = new String[5];

for (int i = 0; i < 5; i++){
    lines[i] = website.readLine();
}

for (int i = 4; i >= 0; i--){
    System.out.println(lines[i]);
}

A better way would be

int lineNum = 5; // or use final keyword
String[] lines = new String[lineNum];

...

for (int i = lines.length; i > 0; i--){
  ... line[i-1]
}

results matching ""

    No results matching ""