using System; class Kata { private static string LANGUAGE = "C#"; public static void Main() { string[] hello = {"H","e","l","l","o"}; Array.ForEach(hello, s => Console.Write(s)); Console.WriteLine(", " + LANGUAGE + "!" ); } }
- using System;
- class Kata
- {
- private static string LANGUAGE = "C#";
- public static void Main()
- {
- string[] hello = {"H","e","l","l","o"};
string result = "";foreach(string s in hello){result = result + s;}- Array.ForEach(hello, s => Console.Write(s));
Console.WriteLine(result + ", " + LANGUAGE + "!" );- Console.WriteLine(", " + LANGUAGE + "!" );
- }
- }
using System; class Kata { private static string LANGUAGE = "C#"; public static void Main() { string[] hello = {"H","e","l","l","o"}; string result = ""; foreach(string s in hello){ result = result + s; } Console.WriteLine(result + ", " + LANGUAGE + "!" ); } }
- using System;
- class Kata
- {
- private static string LANGUAGE = "C#";
- public static void Main()
- {
- string[] hello = {"H","e","l","l","o"};
- string result = "";
for(int i = 0 ; i < hello.Length; i ++){result = result + hello[i];}- foreach(string s in hello){
- result = result + s;
- }
- Console.WriteLine(result + ", " + LANGUAGE + "!" );
- }
- }
You didn't need to use StringBuilder for it but yea Java 11 made it really simple.
public class Kata { public static String multiply(String input,int times){ String str = ""; for(int i = 0; i < times; i++) { str += input; } return str; } }
- public class Kata {
- public static String multiply(String input,int times){
StringBuilder str = new StringBuilder();- String str = "";
- for(int i = 0; i < times; i++) {
str.append(input);- str += input;
- }
return str.toString();- return str;
- }
- }
public class Kumite{ public static String switchout(String in, String replace, String instead){ return in.replaceAll(replace, instead);}}
switchout = str.replace- public class Kumite{
- public static String switchout(String in, String replace, String instead){
- return in.replaceAll(replace, instead);}}
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class Switchout { @Test public void smartToDumb() { assertEquals("I am dumb", Kumite.switchout("I am smart", "smart", "dumb")); } @Test public void yesToNo(){ assertEquals("I am smart? No!", Kumite.switchout("I am smart? Yes!", "Yes", "No")); } }
test.assert_equals(switchout("I am smart", "smart", "dumb"), "I am dumb")test.assert_equals(switchout("Cats are fun", "fun", "evil"), "Cats are evil")- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
- public class Switchout {
- @Test
- public void smartToDumb() {
- assertEquals("I am dumb", Kumite.switchout("I am smart", "smart", "dumb"));
- }
- @Test
- public void yesToNo(){
- assertEquals("I am smart? No!", Kumite.switchout("I am smart? Yes!", "Yes", "No"));
- }
- }
class fizzbuzz { public static String ts(int num){ if(num % 3 == 0 && num % 5 != 0) return "Fizz"; if(num % 3 != 0 && num % 5 == 0) return "Buzz"; if(num % 3 == 0 && num % 5 == 0) return "FizzBuzz"; return String.valueOf(num); } }
def fizzBuzz(num):return 'Fizz' *(not num % 3) + 'Buzz' *(not num % 5) or str(num)- class fizzbuzz {
- public static String ts(int num){
- if(num % 3 == 0 && num % 5 != 0)
- return "Fizz";
- if(num % 3 != 0 && num % 5 == 0)
- return "Buzz";
- if(num % 3 == 0 && num % 5 == 0)
- return "FizzBuzz";
- return String.valueOf(num);
- }
- }
import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void DivisableByThree() { assertEquals("Fizz", fizzbuzz.ts(3)); assertEquals("Fizz", fizzbuzz.ts(12)); } @Test public void DivisableByFive(){ assertEquals("Buzz", fizzbuzz.ts(5)); assertEquals("Buzz", fizzbuzz.ts(95)); } @Test public void DivisableByThreeAndFive(){ assertEquals("FizzBuzz", fizzbuzz.ts(15)); assertEquals("FizzBuzz", fizzbuzz.ts(90)); } @Test public void NotDivisableByThreeOrFive(){ assertEquals("1", fizzbuzz.ts(1)); assertEquals("7", fizzbuzz.ts(7)); } }
test.describe("Divisible By Three")test.assert_equals(fizzBuzz(3), "Fizz")test.assert_equals(fizzBuzz(12), "Fizz")- import org.junit.Test;
- import static org.junit.Assert.assertEquals;
- import org.junit.runners.JUnit4;
test.describe("Divisible By Five")test.assert_equals(fizzBuzz(5), "Buzz")test.assert_equals(fizzBuzz(95), "Buzz")test.describe("Divisible By Three And Five")test.assert_equals(fizzBuzz(15), "FizzBuzz")test.assert_equals(fizzBuzz(90), "FizzBuzz")test.describe("Not Divisible By Three Or Five")test.assert_equals(fizzBuzz(1), "1")test.assert_equals(fizzBuzz(7), "7")- public class SolutionTest {
- @Test
- public void DivisableByThree() {
- assertEquals("Fizz", fizzbuzz.ts(3));
- assertEquals("Fizz", fizzbuzz.ts(12));
- }
- @Test
- public void DivisableByFive(){
- assertEquals("Buzz", fizzbuzz.ts(5));
- assertEquals("Buzz", fizzbuzz.ts(95));
- }
- @Test
- public void DivisableByThreeAndFive(){
- assertEquals("FizzBuzz", fizzbuzz.ts(15));
- assertEquals("FizzBuzz", fizzbuzz.ts(90));
- }
- @Test
- public void NotDivisableByThreeOrFive(){
- assertEquals("1", fizzbuzz.ts(1));
- assertEquals("7", fizzbuzz.ts(7));
- }
- }
def verifySum(s1, s2): if s1 == None or s2 == None or len(s1) == 0 or len(s2) == 0: return None else: return len(s1) == len(s2)
class Kata{public static String verifySum(String nameOne, String nameTwo) {if (nameOne == null || nameTwo == null) return "NULL";else return nameOne.chars().sum() == nameTwo.chars().sum() ? "TRUE" : "FALSE";}}- def verifySum(s1, s2):
- if s1 == None or s2 == None or len(s1) == 0 or len(s2) == 0:
- return None
- else:
- return len(s1) == len(s2)
test.assert_equals(verifySum("boom", "nope"), True) test.assert_equals(verifySum("", "yes"), None) test.assert_equals(verifySum("yeet", "what?"), False) test.assert_equals(verifySum("spaaaaceeee", " "), True) test.assert_equals(verifySum("Sebastian", "Patricia"), False) test.assert_equals(verifySum("Anna", "Nana"), True) test.assert_equals(verifySum("John", None), None)
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;public class SolutionTest {@Testpublic void testName() {assertEquals("FALSE", Kata.verifySum("Sebastian", "Patricia"));assertEquals("TRUE", Kata.verifySum("Anna", "Nana"));assertEquals("NULL", Kata.verifySum("John", null));}}- test.assert_equals(verifySum("boom", "nope"), True)
- test.assert_equals(verifySum("", "yes"), None)
- test.assert_equals(verifySum("yeet", "what?"), False)
- test.assert_equals(verifySum("spaaaaceeee", " "), True)
- test.assert_equals(verifySum("Sebastian", "Patricia"), False)
- test.assert_equals(verifySum("Anna", "Nana"), True)
- test.assert_equals(verifySum("John", None), None)
You get a sentence in a string. Convert every word that has 4 letters or is longer to the word "yeet". If the sentence is longer than 4, it should replace the word with "yeet" but with as many "e"s as there are other letters except the ones on the ends.
It should return the sentence with the words that were changed and the words that weren't changed at the same place as they were before. It should also keep the punctations.
Have fun yeeting words
public class yeet {
public static String yeetWords(String Words){
String[] s = Words.split(" ");
String end = "";
String r = "";
if(s[s.length-1].endsWith(".") || s[s.length-1].endsWith("!") || s[s.length-1].endsWith("?")){
end = s[s.length-1].substring(s[s.length-1].length()-1);
}
for(int i = 0; i<s.length; i++){
String st = s[i];
String rs = "";
int le = st.length()-1;
if(st.length() >= 4){
if(st.endsWith(end)){
le = le-1;
}
rs = "y" + st.substring(1,1);
for(int e = 1; e<le; e++){
rs = rs + "e";
}
rs = rs + "t";
} else {
rs = st;
}
r = r + rs + " ";
}
return r.trim() + end;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals("I yeet to yeet yeet yeeet yeet yeeeeeeeeeeeeeeet!",yeet.yeetWords("I like to yeet long words like facetrackingdrone!"));
}
}
wenn der übergebenen string mit a anfängt, gebe true zurück
public class test{
public static Boolean anfanga(String s){
if(s.startsWith("a")){
return true;
} else {
return false;
}
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals(true, test.anfanga("arbeit"));
assertEquals(false, test.anfanga("text"));
}
}