Advertisement
ReasonablyGood

Untitled

Jul 9th, 2025
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. private String buildFizzBuzz(int from, int to)
  2. {
  3.     StringBuilder sb = new StringBuilder();
  4.     Boolean hasWordThisLoop;
  5.    
  6.     for( int i=from; i<=to; i++)
  7.     {
  8.         hasWordThisLoop = false;
  9.         if( i % 3 == 0)
  10.         {
  11.             sb.append("Fizz");
  12.             hasWordThisLoop = true;
  13.         }
  14.         if( i % 5 == 0)
  15.         {
  16.             sb.append("Fizz");
  17.             hasWordThisLoop = true;
  18.         }
  19.         if (!hasWordThisLoop)
  20.         {
  21.             sb.append(i);
  22.         }
  23.  
  24.         sb.append('\n');
  25.     }
  26.  
  27.     return sb.toString();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement