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
//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
//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
//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
// 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
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))) | |
} | |
} |
NewerOlder