Skip to content

Instantly share code, notes, and snippets.

View joanmolinas's full-sized avatar
🎯
Focusing

Joan Molinas joanmolinas

🎯
Focusing
View GitHub Profile
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;
//Student mark class
class StudentMark implements Comparable<StudentMark>{
int mark;
StudentMark(int mark) {
this.mark = mark;
}
@Override
public String toString() {
return "Student [mark=" + mark + "]";
}
//Student Class
class Student {
String name;
Student(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [name=" + name + "]";
}
//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);
}
// 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';
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)))
}
}