Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views3 pages

Java Programs: Even/Odd, Factorial, Patterns

Uploaded by

Durga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java Programs: Even/Odd, Factorial, Patterns

Uploaded by

Durga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a java program to check whether a number is even or odd

import java.io.*;

public class EvenOdd {

public static void main(String[] args) {

int num ;

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());

if(num % 2 == 0)

System.out.println(num + ” is even.”);

else

System.out.println(num + ” is odd.”);

Write a java program to find the factorial of a number

import java.io.*;

public class Factorial {

public static void main(String[] args)

int num , factorial = 1;

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

num=Integer.parseInt(br.readLine());

for(int i = 1; i <= num; ++i) {

factorial *= i;

System.out.println(“Factorial of ” + num + ” is: ” + factorial);

}
Write a java program to print pattern: *

**

***

import java.io.*;

public class PrintPattern {

public static void main(String[] args) {

int rows ;

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

rows=Integer.parseInt(br.readLine());

for (int i = 1; i <= rows; ++i) {

for (int j = 1; j <= i; ++j) {

System.out.print(“* “);

System.out.println();

Write a java program to print pattern: 1

12

123

import java.io.*;

public class PrintPattern {

public static void main(String[] args) {

int rows ;

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

rows=Integer.parseInt(br.readLine());
for (int i = 1; i <= rows; ++i) {

for (int j = 1; j <= i; ++j) {

System.out.print(j+” “);

System.out.println();

Write a java program to print pattern: 1

22

333

import java.io.*;

public class PrintPattern {

public static void main(String[] args) {

int rows ;

BufferedReader br=new BufferedReader(new InputStreamReader (System.in));

rows=Integer.parseInt(br.readLine());

for (int i = 1; i <= rows; ++i) {

for (int j = 1; j <= i; ++j) {

System.out.print(i+” “);

System.out.println();

You might also like