0% found this document useful (0 votes)
19 views

Programs

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)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Programs

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)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*; class PrimeNumber { public static void main(String[] args) throws Exception { int i; BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter number:"); int num = Integer.parseInt(br.readLine()); System.out.println("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){ System.out.print(" "+i); } } } }
import java.io.*; class Factorial{

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

import java.io.*; public class IfElse {

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

int n; DataInputStream in = new DataInputStream (System.in); n = Integer.parseInt(in.readLine()); if (n % 2 == 0) { System.out.println("Given number is Even."); } else { System.out.println("Given number is Odd."); } } }

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

You might also like