Created
March 29, 2016 09:11
-
-
Save sivabudh/1c9ce578022ef6a87f1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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