Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. public String toString() {
  2. String cardString = "";
  3. for (PlayingCard c : this.list) // <--
  4. {
  5. cardString = cardString + c + "n";
  6. }
  7.  
  8. label: for (int i = 0; i < x; i++) {
  9. for (int j = 0; j < i; j++) {
  10. if (something(i, j)) break label; // jumps out of the i loop
  11. }
  12. }
  13. // i.e. jumps to here
  14.  
  15. int a = (b < 4)? 7: 8; // if b < 4, set a to 7, else set a to 8
  16.  
  17. String[] ss = {"hi", "there"}
  18. for (String s: ss) {
  19. print(s); // output "hi" , and "there" on the next iteration
  20. }
  21.  
  22. int a = factorial(b);
  23. assert a >= 0: "factorial may not be less than 0"; // throws an AssertionError with the message if the condition evaluates to false
  24.  
  25. switch (type) {
  26. case WHITESPACE:
  27. case RETURN:
  28. break;
  29. case NUMBER:
  30. print("got number: " + value);
  31. break;
  32. default:
  33. print("syntax error");
  34. }
  35.  
  36. class Person {
  37. public static int compareByAge(Person a, Person b) {
  38. return a.birthday.compareTo(b.birthday);
  39. }}
  40. }
  41.  
  42. Arrays.sort(persons, Person::compareByAge);
  43.  
  44. int x = bigInt ? 10000 : 50;
  45.  
  46. double[] vals = new double[100];
  47. //fill x with values
  48. for (double x : vals) {
  49. //do something with x
  50. }
  51.  
  52. public String toString() {
  53. String cardString = "";
  54. for (Iterator<PlayingCard> it = this.list.iterator(); it.hasNext(); /**/) {
  55. PlayingCard c = it.next();
  56. cardString = cardString + c + "n";
  57. }
  58. }
  59.  
  60. for (String name : names) {
  61. // remainder omitted
  62. }
  63.  
  64. for (Object o: list)
  65. {
  66. // o is an element of list here
  67. }
  68.  
  69. String cardString = "";
  70. for (PlayingCard c : this.list) // <--
  71. {
  72. cardString = cardString + c + "n";
  73. }
  74.  
  75. 2S
  76. 3H
  77. 4S
  78.  
  79. variable = `condition ? result 1 : result 2;`
  80.  
  81. boolean isNegative = number > 0 ? false : true;
  82.  
  83. if(number > 0){
  84. isNegative = false;
  85. }
  86. else{
  87. isNegative = true;
  88. }
  89.  
  90. public void someFunction(){
  91. //an infinite loop
  92. goBackHere: { //label
  93. for(int i = 0; i < 10 ;i++){
  94. if(i == 9 ) continue goBackHere;
  95. }
  96. }
  97. }
  98.  
  99. JLabel[] labels = {new JLabel(), new JLabel(), new JLabel()};
  100.  
  101. for ( JLabel label : labels )
  102. {
  103. label.setText("something");
  104.  
  105. panel.add(label);
  106. }
  107.  
  108. final List<String> list = new ArrayList<String>();
  109. for (final String s : list)
  110. {
  111. System.out.println(s);
  112. }
  113.  
  114. list.isEmpty() ? true : false;
  115.  
  116. int minVal = (a < b) ? a : b;
  117.  
  118. int minval;
  119. if(a < b){ minval = a;}
  120. else{ minval = b; }
  121.  
  122. for(Node n : List l){ ... }
  123.  
  124. for(Node n = l.head; n.next != null; n = n.next)
  125.  
  126. import java.util.*;
  127.  
  128. class ForEachLoop
  129. {
  130. public static void main(String args[])
  131. {`enter code here`
  132. Integer[] iray={1,2,3,4,5};
  133. String[] sray={"ENRIQUE IGLESIAS"};
  134. printME(iray);
  135. printME(sray);
  136.  
  137. }
  138. public static void printME(Integer[] i)
  139. {
  140. for(Integer x:i)
  141. {
  142. System.out.println(x);
  143. }
  144. }
  145. public static void printME(String[] i)
  146. {
  147. for(String x:i)
  148. {
  149. System.out.println(x);
  150. }
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement