Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,209,018 members, 8,004,616 topics. Date: Saturday, 16 November 2024 at 09:05 PM |
Nairaland Forum / Science/Technology / Programming / Solve The Fizz - Buzz Hackerrank Challenge In Both Java And Javascript (445 Views)
Can Some Explain This Hackerrank Question For Me please(pics) / Fizz Buzz / After 10days Of Coding With Html, Css And Javascript Forum4africa Is Ready (2) (3) (4)
(1) (Reply)
Solve The Fizz - Buzz Hackerrank Challenge In Both Java And Javascript by kemi72: 4:24pm On Nov 18, 2023 |
Solve the fizzbuzz hackerrank challenge question: Given a number n, for each integer i in the range from 1 to n inclusive, print out one value per line as follows: if i is a multiple of both 3 and 5, print FizzBuzz if i is a multiple of 3(but not 5), print Fizz if i is a multiple of 5(but not 3), print Buzz if i is not a multiple of 3 or 5, print the value of i Java Solution import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result { /* * Complete the 'fizzBuzz' function below. * * The function accepts INTEGER n as parameter. */ public static void fizzBuzz(int n) { for(int i=1; i<=n; i++){ if(i%3 == 0 && i%5 == 0){ System.out.println("FizzBuzz" }else if(i%3 == 0){ System.out.println("Fizz" }else if(i%5 == 0){ System.out.println("Buzz" }else{ System.out.println(i); } } } } public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bufferedReader.readLine().trim()); Result.fizzBuzz(n); bufferedReader.close(); } } Read more for Javascript solution: https://codeflarelimited.com/blog/fizzbuzz-hackerrank-challenge/
|
(1) (Reply)
. / Have You Ever Gotten A Job Through Linkedin, Share Your Experience / Help Tech Family.. Its Hard Understanding Backend Progr. With Node Js For Me ..
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8 |