Results 1 to 1 of 1
Thread: If statement demo
-
If statement demo
This program plays the game "Fizzbuzz". It counts to 100, replacing each multiple of 5 with the word "fizz", each multiple of 7 with the word "buzz",
and each multiple of both with the word "fizzbuzz". It uses the modulo operator (%) to determine if a number is divisible by another.
Java Code:public class FizzBuzz { // Everything in Java is a class public static void main(String[] args) { // Every program must have main() for (int i = 1; i <= 100; i++) { // count from 1 to 100 if (((i % 5) == 0) && ((i % 7) == 0)) // Is it a multiple of 5 & 7? System.out.print("fizzbuzz"); else if ((i % 5) == 0) // Is it a multiple of 5? System.out.print("fizz"); else if ((i % 7) == 0) // Is it a multiple of 7? System.out.print("buzz"); else System.out.print(i); // Not a multiple of 5 or 7 System.out.print(" "); } System.out.println(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
If Else Demo
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:04 PM -
Simple demo of CSV matching using Regular Expressions
By Java Tip in forum java.utilReplies: 0Last Post: 04-16-2008, 10:59 PM -
code for making a java swing program a demo verson
By fakhruddin in forum AWT / SwingReplies: 1Last Post: 11-27-2007, 08:54 PM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 04:45 PM -
If Statement
By aDrizzle in forum New To JavaReplies: 4Last Post: 07-08-2007, 08:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks