class Solution {
static def max(a : double, b : double, c : double) {
if (a > b && a > c) {
return a
}
if (b > c) {
return b
}
return c
}
}
import java.util.List
class Solution {
static def sum(list : List<Double>) : double {
var sum = 0.0
for (num : list) {
sum += num
}
return sum
}
}
import java.util.List
class Solution {
static def mul(list : List<Double>) : double {
var mul = 0.0
for (num : list) {
mul *= num
}
return mul
}
}
class Solution {
static def reverse(value : String) : String {
var rev = new StringBuilder
for (c : value.toCharArray) {
rev.insert(0, c)
}
return rev.toString
}
}
class Solution {
static def fact(n : int) : int {
if (n > 0) {
return fact(n - 1) * n
}
return 1
}
}
class Solution1 {
static def inRange(n : int, start : int, end : int) : boolean {
start <= n && n <= end
}
}
class Solution2 {
static def inRange(n : int, start : int, end : int) : boolean {
(start .. end).contains(n)
}
}
import static extension java.lang.Character.*
class Solution {
static def caseCount(value : String) : void {
var lcount = 0
var ucount = 0
for (c : value.toCharArray) {
if (c.isUpperCase) {
ucount++
} else if (c.isLowerCase) {
lcount++
}
}
println("No. of Upper case characters : " + ucount)
println("No. of Lower case Characters : " + lcount)
}
}
import java.util.List
class Solution1 {
static def disctinct(list : List<Integer>) : List<Integer> {
var uniq = newArrayList
for (c : list) {
if (!uniq.contains(c)) {
uniq += c
}
}
return uniq
}
}
class Solution2 {
static def disctinct(list : List<Integer>) : List<Integer> {
var uniq = newTreeSet(null)
uniq.addAll(list)
return newArrayList(uniq)
}
}
class Solution {
static def isPrime(n : int) : boolean {
if (n == 1) {
return false
} else if (n == 2) {
return true
}
for (x : 2..<n) {
if (n % x == 0) {
return false
}
}
return true
}
}
import java.util.List
class Solution {
static def showEvenNumberList(list : List<Integer>) : void {
var evenNums = newArrayList
for (num : list) {
if (num % 2 == 0) {
evenNums += num
}
}
println(evenNums)
}
}
class Solution {
static def isPerfect(n : int) : boolean {
var sum = 0
for (x : 1..<n) {
if (n % x == 0) {
sum += x
}
}
sum == n
}
}
class Solution {
static def isPalindrome(value : String) : boolean {
var i = 0
var j = value.length - 1
while (i < j) {
if (value.charAt(i) != value.charAt(j)) {
return false
}
}
return true
}
}
import static extension java.lang.Character.*
class Solution {
static def isPangram(value : String) : boolean {
if (value.length < 26) {
return false
}
var found = newTreeSet(null)
for (c : value.toCharArray) {
if (found.size == 26) {
return true
}
if (c.isLetter) {
found += c.toLowerCase
}
}
return found.size == 26
}
}
import static extension java.util.Collections.sort;
class Solution {
static def sortWords(value : String) {
var components = newArrayList(value.split("\-"))
components.sort
var result = String.join('-', components)
println(result)
}
}
class Solution {
static def showSquareNumbers {
var numbers = newArrayList
for (num : 1..30) {
numbers += num**2
}
println(numbers)
}
}
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.