Java Challenges
How Edabit Works
This is an introduction to how challenges on Edabit work. In the code editor below you'll see a starter function that looks like this: public static boolean returnTrue() { } All you have to do is type return true; between the curly braces { } and then click the Check button. If you did this correctly, a celebration window will pop up. Notes If you get stucReturn the Sum of Two Numbers
Create a method that takes two integers as arguments and returns their sum. Examples sum(3, 2) ➞ 5 sum(-3, -6) ➞ -9 sum(7, 3) ➞ 10 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Convert Minutes into Seconds
Write a function that takes an integer minutes and converts it to seconds. Examples convert(5) ➞ 300 convert(3) ➞ 180 convert(2) ➞ 120 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Return the Next Number from the Integer Passed
Create a function that takes a number as an argument, increments the number by +1 and returns the result. Examples addition(0) ➞ 1 addition(9) ➞ 10 addition(-3) ➞ -2 Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the Solutions tab.Are the Numbers Equal?
Create a function that returns true when num1 is equal to num2; otherwise return false. Examples isSameNum(4, 8) ➞ false isSameNum(2, 2) ➞ true isSameNum(42, 32) ➞ false Notes Don't forget to return the result.Upvotes vs Downvotes
Given an object containing counts of both upvotes and downvotes, return what vote count should be displayed. This is calculated by subtracting the number of downvotes from upvotes. Examples getVoteCount({ upvotes: 13, downvotes: 0 }) ➞ 13 getVoteCount({ upvotes: 2, downvotes: 33 }) ➞ -31 getVoteCount({ upvotes: 132, downvotes: 132 }) ➞ 0 Notes You can expeConvert Hours into Seconds
Write a function that converts hours into seconds. Examples howManySeconds(2) ➞ 7200 howManySeconds(10) ➞ 36000 howManySeconds(24) ➞ 86400 Notes 60 seconds in a minute, 60 minutes in an hour Don't forget to return your answer.Find the Perimeter of a Rectangle
Create a function that takes length and width and finds the perimeter of a rectangle. Examples findPerimeter(6, 7) ➞ 26 findPerimeter(20, 10) ➞ 60 findPerimeter(2, 9) ➞ 22 Notes Don't forget to return the result. If you're stuck, find help in the Resources tab. If you're really stuck, find solutions in the Solutions tab.Power Calculator
Create a function that takes voltage and current and returns the calculated power. Examples power(230, 10) ➞ 2300 power(110, 3) ➞ 330 power(480, 20) ➞ 9600 Notes power is voltage multiplied by current.Will the Next File Fit?
A drive has capacity megabytes of space, and used megabytes are already taken. Create fileFits to return true if a file of size megabytes will fit. Otherwise, return false. Filling the drive exactly is allowed. Examples Program.fileFits(100, 70, 20) // true Program.fileFits(100, 70, 31) // false Program.fileFits(100, 70, 30) // true Notes All three numbeName That Playlist
Give your playlist a name to match its mood. Create playlistName to return mood followed by " Mix". For "Late Night", return "Late Night Mix". Examples Program.playlistName("Late Night") // "Late Night Mix" Program.playlistName("Focus") // "Focus Mix" Program.playlistName("Rainy Day") // "Rainy Day Mix" Notes mood is a nonempty string of at most 30 charaOne More Encore
The crowd wants one more song! Create encoreTotal to return the total number of songs after the band adds one encore to songs. Examples Program.encoreTotal(8) // 9 Program.encoreTotal(0) // 1 Program.encoreTotal(20) // 21 Notes songs is a whole number from 0 to 100. The encore always adds exactly one song.Make It a Hashtag
Turn one word into a hashtag. Create makeHashtag to put "#" before word and return the new string. Keep the word just as it is. Examples Program.makeHashtag("coding") // "#coding" Program.makeHashtag("PixelArt") // "#PixelArt" Program.makeHashtag("X") // "#X" Notes word contains 1 to 20 English letters, with no spaces or existing #. Do not change its capRetry or Stop?
Create shouldRetry to decide whether to try a request again. Return true only when the previous attempt failed and attempts is less than limit. Otherwise, return false. Examples Program.shouldRetry(true, 2, 3) // true Program.shouldRetry(false, 2, 3) // false Program.shouldRetry(true, 3, 3) // false Notes failed is a boolean. attempts is the number of atPlayer Two Has Joined
Someone has joined your game! Create joinMessage to return their username followed by " has joined!". For "Nova", return "Nova has joined!". Examples Program.joinMessage("Nova") // "Nova has joined!" Program.joinMessage("Pixel_7") // "Pixel_7 has joined!" Program.joinMessage("x") // "x has joined!" Notes username contains 1 to 20 English letters, digitsAre the Numbers Equal?
Create a function that takes two integers and checks if they are equal. Examples isEqual(5, 6) ➞ false isEqual(1, 1) ➞ true isEqual(36, 35) ➞ false Notes N/AMaximum Edge of a Triangle
Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Examples nextEdge(8, 10) ➞ 17 nextEdge(5, 7) ➞ 11 nextEdge(9, 2) ➞ 10 Notes (side1 + side2) - 1 = maximum range of third edge. The side lengths of the triangle are positive integers. Don't forget to return the result.Area of a Triangle
Write a function that takes the base and height of a triangle and return its area. Examples triArea(3, 2) ➞ 3 triArea(7, 4) ➞ 14 triArea(10, 10) ➞ 50 Notes The area of a triangle is: (base * height) / 2 Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you're really stuck, unlock solutions in the SolutioIs the Number Less than or Equal to Zero?
Create a method that takes an integer as its only argument and returns true if it's less than or equal to zero, otherwise return false. Examples lessThanOrEqualToZero(5) ➞ false lessThanOrEqualToZero(0) ➞ true lessThanOrEqualToZero(-2) ➞ true Notes Don't forget to return the result. If you get stuck on a challenge, find help in the Resources tab. If you'reReturn the Remainder from Two Numbers
There is a single operator in Java, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value. Examples remainder(1, 3) ➞ 1 remainder(3, 4) ➞ 3 remainder(-9, 45) ➞ -9 remainder(5, 5) ➞ 0 Notes The tests only u