Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String toString() {
- String cardString = "";
- for (PlayingCard c : this.list) // <--
- {
- cardString = cardString + c + "n";
- }
- label: for (int i = 0; i < x; i++) {
- for (int j = 0; j < i; j++) {
- if (something(i, j)) break label; // jumps out of the i loop
- }
- }
- // i.e. jumps to here
- int a = (b < 4)? 7: 8; // if b < 4, set a to 7, else set a to 8
- String[] ss = {"hi", "there"}
- for (String s: ss) {
- print(s); // output "hi" , and "there" on the next iteration
- }
- int a = factorial(b);
- assert a >= 0: "factorial may not be less than 0"; // throws an AssertionError with the message if the condition evaluates to false
- switch (type) {
- case WHITESPACE:
- case RETURN:
- break;
- case NUMBER:
- print("got number: " + value);
- break;
- default:
- print("syntax error");
- }
- class Person {
- public static int compareByAge(Person a, Person b) {
- return a.birthday.compareTo(b.birthday);
- }}
- }
- Arrays.sort(persons, Person::compareByAge);
- int x = bigInt ? 10000 : 50;
- double[] vals = new double[100];
- //fill x with values
- for (double x : vals) {
- //do something with x
- }
- public String toString() {
- String cardString = "";
- for (Iterator<PlayingCard> it = this.list.iterator(); it.hasNext(); /**/) {
- PlayingCard c = it.next();
- cardString = cardString + c + "n";
- }
- }
- for (String name : names) {
- // remainder omitted
- }
- for (Object o: list)
- {
- // o is an element of list here
- }
- String cardString = "";
- for (PlayingCard c : this.list) // <--
- {
- cardString = cardString + c + "n";
- }
- 2S
- 3H
- 4S
- variable = `condition ? result 1 : result 2;`
- boolean isNegative = number > 0 ? false : true;
- if(number > 0){
- isNegative = false;
- }
- else{
- isNegative = true;
- }
- public void someFunction(){
- //an infinite loop
- goBackHere: { //label
- for(int i = 0; i < 10 ;i++){
- if(i == 9 ) continue goBackHere;
- }
- }
- }
- JLabel[] labels = {new JLabel(), new JLabel(), new JLabel()};
- for ( JLabel label : labels )
- {
- label.setText("something");
- panel.add(label);
- }
- final List<String> list = new ArrayList<String>();
- for (final String s : list)
- {
- System.out.println(s);
- }
- list.isEmpty() ? true : false;
- int minVal = (a < b) ? a : b;
- int minval;
- if(a < b){ minval = a;}
- else{ minval = b; }
- for(Node n : List l){ ... }
- for(Node n = l.head; n.next != null; n = n.next)
- import java.util.*;
- class ForEachLoop
- {
- public static void main(String args[])
- {`enter code here`
- Integer[] iray={1,2,3,4,5};
- String[] sray={"ENRIQUE IGLESIAS"};
- printME(iray);
- printME(sray);
- }
- public static void printME(Integer[] i)
- {
- for(Integer x:i)
- {
- System.out.println(x);
- }
- }
- public static void printME(String[] i)
- {
- for(String x:i)
- {
- System.out.println(x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement