Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created March 29, 2016 09:11
Show Gist options
  • Save sivabudh/1c9ce578022ef6a87f1c to your computer and use it in GitHub Desktop.
Save sivabudh/1c9ce578022ef6a87f1c to your computer and use it in GitHub Desktop.
// Write a program that finds all prime numbers up to n for input n
import java.util.Scanner;
class Untitled {
public static void main(String[] args) {
// FizzBuzz
boolean tree = false;
boolean five = false;
for (int i = 1; i <= 100; i++) {
if (i%3.0 == 0) tree = true;
if (i%5.0 == 0) five = true;
if (tree & five) System.out.println("Fish and Buzz");
else if (tree) System.out.println("Fish");
else if (five) System.out.println("Buzz");
else System.out.println(String.valueOf(i));
tree = false;
five = false;
}
// Find prime number from n to n
System.out.print("Please input number: ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i <= n; i++) {
if (i == 0) continue;
if (i % 2 != 0) System.out.println(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment