0% found this document useful (0 votes)
11 views2 pages

Java Programs: Prime, Factorial, Even/Odd

The document contains code snippets for several Java programs: a prime number checker that takes user input and prints prime numbers up to that value, a factorial calculator that takes a number from the user and prints its factorial, an even/odd checker that determines if a user input number is even or odd, and questions asking to write programs to generate the Fibonacci sequence and find the biggest of two numbers.

Uploaded by

saleem010
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Java Programs: Prime, Factorial, Even/Odd

The document contains code snippets for several Java programs: a prime number checker that takes user input and prints prime numbers up to that value, a factorial calculator that takes a number from the user and prints its factorial, an even/odd checker that determines if a user input number is even or odd, and questions asking to write programs to generate the Fibonacci sequence and find the biggest of two numbers.

Uploaded by

saleem010
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

import [Link].

*; class PrimeNumber { public static void main(String[] args) throws Exception { int i; BufferedReader br = new BufferedReader( new InputStreamReader([Link])); [Link]("Enter number:"); int num = [Link]([Link]()); [Link]("Prime number: "); for (i=1; i < num; i++ ){ int j; for (j=2; j<i; j++){ int n = i%j; if (n==0){ break; } } if(i == j){ [Link](" "+i); } } } }
import [Link].*; class Factorial{

public static void main(String[] args) { try{ DataInputStream object=new DataInputStream([Link]); [Link]("enter the number"); int a= [Link]([Link]()); int fact= 1; [Link]("Factorial of " +a+ ":"); for (int i= 1; i<=a; i++){ fact=fact*i; } [Link](fact); } catch (Exception e){} } }

import [Link].*; public class IfElse {

public static void main(String[] args) throws IOException

int n; DataInputStream in = new DataInputStream ([Link]); n = [Link]([Link]()); if (n % 2 == 0) { [Link]("Given number is Even."); } else { [Link]("Given number is Odd."); } } }

WAP for Fibonacci Sequence ? WAP for biggest among two numbers?

You might also like