I compared Java and Ruby's FizzBuzz.

I compared Java and Ruby's FizzBuzz. ]

Java is used as the development language for business. Outside of work, I create portfolios in Ruby.

Java, Ruby FizzBuzz

FizzBuzz is a program that displays from one number to another on the screen. However, there are the following conditions. ・ When it is a multiple of 3, it is displayed as Fizz instead of a number. ・ When it is a multiple of 5, Buzz is displayed instead of the number. ・ When it is a multiple of 15, FizzBuzz is displayed instead of the number.

Java

class FizzBuzz {
  public static void main(String args[]) {
    for (int i = 1; i <= 15; i++) {
      if (i % 15 == 0) {
        System.out.printIn("FizzBuzz");
      } else if (i % 3 == 0) {
        System.out.printIn("Fizz");
      } else if (i % 5 == 0) {
        System.out.printIn("Buzz");
      } else {
        System.out.printIn(i);
      }
    }
  }
}

Ruby

(1..15).each do |i|

  if i % 15 == 0
    puts 'FizzBuzz'
  elsif i % 3 == 0
    puts 'Fizz'
  elsif i % 5 == 0
    puts 'Buzz'
  else
    puts i
  end

end

Recommended Posts

I compared Java and Ruby's FizzBuzz.
I compared PHP and Java constructors
I compared the characteristics of Java and .NET
A Java engineer compared Swift, Kotlin, and Java.
Object-oriented FizzBuzz (Java)
Java and JavaScript
XXE and Java
I tried FizzBuzz.
FizzBuzz in Java
I compared classes and instances with worldly things
I studied for 3 weeks and passed Java Bronze
I tried Mastodon's Toot and Streaming API in Java
Getters and setters (Java)
I first touched Java ②
[Java] Thread and Runnable
Java true and false
I first touched Java ③
[Java] String comparison and && and ||
Java --Serialization and Deserialization
[Java] Arguments and parameters
I summarized the types and basics of Java exceptions
I want to transition screens with kotlin and java!
I first touched Java
[Java] Branch and repeat
[Java] Variables and types
Difference between i ++ and ++ i
java (classes and instances)
[Java beginner] Difference between length and length () ~ I don't know ~
[Java] Overload and override
Regarding the difference between Java array and ArrayList, I compared and corresponded methods with similar functions.
I didn't understand the behavior of Java Scanner and .nextLine ().
I tried to collect and solve Ruby's "class" related problems.
I tried to summarize the basics of kotlin and java
I want to make a list with kotlin and java!
What I learned in Java (Part 4) Conditional branching and repetition
I want to make a function with kotlin and java!
I tried to make Java Optional and guard clause coexist
[Java] I tried access modifier public and unspecified field access [Eclipse]
I want to implement various functions with kotlin and java!
[Java] I thought about the merits and uses of "interface"
Study Java # 2 (\ mark and operator)
What I researched about Java 8
Java version 8 and later features
I started Java Gold (Chapter 1-1)
What I researched about Java 6
[Java] Difference between == and equals
[Java] Stack area and static area
[Java] Generics classes and generics methods
Java programming (variables and data)
Java encryption and decryption PDF
I made roulette in Java.
What I researched about Java 9
I investigated Java primitive types
I took Java SE8 Gold.
Java class definition and instantiation
I tried Drools (Java, InputStream)
[Java] About String and StringBuilder
[Java] HashCode and equals overrides
☾ Java / Iterative statement and iterative control statement
What I researched about Java 7
I tried using Java REPL