python code learnifndgdsaj
fdkajfklajskfasl
fdflafdkalflaklfls
ArraysBreak / Continue
Animal [] zoo = new Animal [4];
zoo [0] = new Tiger();
zoo [1] = new Giraffe();
…for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
//This skips the value of 4
}
if (i == 6) {
break;
//This jumps out of the for loop
}
}
String [] cars = {"Volvo", "BMW", "Ford", "Mazda"};
[Link]([Link]);
//Outputs 4
int [][] myNumbers = {{1, 2, 3, 4}, {4, 5, 6}};
int x = myNumbers [1][2];
[Link](x);
//Outputs 6
If...Else
[Link](cars);
[Link]([Link](cars));
//[BMW, Ford, Mazda, Volvo]
SORTING OBJECTS WITH MULTIPLE PARAMETERS:
NATURAL SORTING
(Created within class)
public class Person implements Comparable<Person>{…
@Override
public int compareTo(Person o) {
return [Link]([Link], [Link]);
}
----> Use wrapperclass
int time = 22;
if (time < 10) {
[Link]("Good morning!");
} else if (time < 20) {
[Link]("Good day!");
} else {
[Link]("Good evening!");
}
//Outputs "Good evening!"
variable = (condition) ? expressionTrue :
[Link](listOfPeople);
/
[Link](...);
ALTERNATIVE SORTING
(Created in sepparate class)
public class SortOnName implements Comparator<Person>{
@Override
public int compare(Person o1, Person o2) {
return [Link]().compareTo([Link]());