This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Float { | |
static func randomFloat(range : ClosedInterval<Float>) -> Float { | |
return range.start + (range.end - range.start) * Float(Float(arc4random()) / Float(UInt32.max)) | |
} | |
} | |
extension Int { | |
static func randomInt(range : ClosedInterval<Int>) -> Int { | |
return range.start + Int(arc4random_uniform(UInt32(range.end - range.start + 1))) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Know if word is palindrome | |
// System.out.println((isPalindrome(palindrome) ? "Yes" : "No")); -> Output "Yes" | |
public static boolean isPalindrome(String s) { | |
String word = new StringBuilder(s).reverse().toString(); | |
return word.equalsIgnoreCase(s); | |
} | |
// Know number of characters contains this word | |
// String word = "Palangana"; | |
// char character = 'a'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Module of a vector | |
Vector<Integer> moduleVector = new Vector<Integer>(10); | |
for (int i = 0; i < 10; i++) { | |
moduleVector.add(randInt(-100, 100)); | |
} | |
double module = 0; | |
for (Integer i : moduleVector) { | |
module += Math.pow(i, 2); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Student Class | |
class Student { | |
String name; | |
Student(String name) { | |
this.name = name; | |
} | |
@Override | |
public String toString() { | |
return "Student [name=" + name + "]"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Student mark class | |
class StudentMark implements Comparable<StudentMark>{ | |
int mark; | |
StudentMark(int mark) { | |
this.mark = mark; | |
} | |
@Override | |
public String toString() { | |
return "Student [mark=" + mark + "]"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student implements Serializable { | |
private String name; | |
private int mark; | |
//if attribute contains transient, not save. | |
transient private String city; | |
public Student(String name, int mark, String city) { | |
this.name = name; | |
this.mark = mark; | |
this.city = city; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For use Gson, you need a Gson jar. Download from this https://code.google.com/p/google-gson/ | |
class Student { | |
private String name; | |
private int mark; | |
private String city; | |
public Student(String name, int mark, String city) { | |
this.name = name; | |
this.mark = mark; | |
this.city = city; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//REQUIRE PARSE | |
var Parse = require('parse').Parse; | |
//ADD NECESSARY KEYS - FOR MODIFY IS NECESSARY MASTER KEY | |
Parse.initialize(APP_KEY, JSC_KEY, MASTER_KEY); | |
//YOU HAVE USE THIS COMMAND FOR USE MASTER KEY | |
Parse.Cloud.useMasterKey(); | |
var UserClass = Parse.Object.extend('_User'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Enum | |
enum Country { | |
case Spain, France | |
} | |
//Classes | |
class Spain : Language { | |
func code() -> String { | |
return "SP" | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in 1...10{ | |
switch (i) { | |
case let x where x%2 == 0: | |
println("even") | |
case let x where x%2 != 0: | |
println("odd") | |
default: | |
break; | |
} | |
} |
OlderNewer