Skip to content

Instantly share code, notes, and snippets.

@kaiimran
Created June 4, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaiimran/630af5db136ad32c77f4f3c2279e5d22 to your computer and use it in GitHub Desktop.
Save kaiimran/630af5db136ad32c77f4f3c2279e5d22 to your computer and use it in GitHub Desktop.
Write a short program that prints each number from 1 to 180 on a new line. For each multiply of 3, print "Involve" instead of the number. For each multiply of 5, print "Asia" instead of the number. For numbers which are multiply of both 3 and 5, print "InvolveAsia" instead of the number.
import java.io.*;
public class InvolveAsia{
public static void main(String []args){
involveAsia(180);
}
static void involveAsia(int n)
{
for (int i=1; i<=n; i++)
{
String s = "";
if(i % 3 == 0)
{
s = s + "Involve";
}
if(i % 5 == 0)
{
s = s + "Asia";
}
if (s == "")
{
System.out.println(i);
}
else
{
System.out.println(s);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment