public class NamesAndNumbers{ public static String run(int[]numbers, String[] names){ String outputValue = "error"; if(numbers == null || names == null) { return "array is null"; } else if(numbers.length == 0 || names.length == 0) { return "length is zero"; } return outputValue; } }//end class.
- public class NamesAndNumbers{
- public static String run(int[]numbers, String[] names){
return "";- String outputValue = "error";
- if(numbers == null || names == null) {
- return "array is null";
- } else if(numbers.length == 0 || names.length == 0) {
- return "length is zero";
- }
- return outputValue;
- }
- }//end class.
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; class SolutionTest { @Test void lengthIsntZeroTest() { assertEquals("length is zero", NamesAndNumbers.run(new int[1], new String[0])); assertNotEquals("length is zero", NamesAndNumbers.run(new int[1], new String[1])); } @Test void arrayIsntNullTest() { String[]arrStr = null; assertEquals("array is null", NamesAndNumbers.run(new int[1], arrStr)); assertNotEquals("array is null", NamesAndNumbers.run(new int[1], new String[1])); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertNotEquals;
// TODO: Replace examples and use TDD by writing your own tests- class SolutionTest {
@Testvoid testSomething() {}- @Test
- void lengthIsntZeroTest() {
- assertEquals("length is zero", NamesAndNumbers.run(new int[1], new String[0]));
- assertNotEquals("length is zero", NamesAndNumbers.run(new int[1], new String[1]));
- }
- @Test
- void arrayIsntNullTest() {
- String[]arrStr = null;
- assertEquals("array is null", NamesAndNumbers.run(new int[1], arrStr));
- assertNotEquals("array is null", NamesAndNumbers.run(new int[1], new String[1]));
- }
- }
Given an array of strings and an array of ints, associate them from longest to shortest according to the length of each string. The output format must be a string with the syntax:
- name1:number1,name2:number2,name3:number3... nameN:numberN
Input example: - String[]names = {"Ana", "Miguel", "Josemanuel"}
- int[]numbers = {1034, 21, 537}
Output example: - "JoseManuel:1034,Miguel:537,Ana:21"
public class NamesAndNumbers{
public static String run(int[]numbers, String[] names){
return "";
}
}//end class.
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
}
}