# lab programs

## Java program to display triangle 1 23 456 78910

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /* Display Triangle as follow : BREAK DEMO. 1 2 3 4 5 6 7 8 9 10 … N */ class Output1{ public static void main(String args[]){ int c=0; int n = […]

## Java program to find average of consecutive N Odd no. and Even no.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 class EvenOdd_Avg{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0; while(n > 0){ if(n%2==0){ cntEven++; sumEven = sumEven + n; } else{ cntOdd++; sumOdd = sumOdd + n; } n–; […]

## Java program to generate Harmonic Series 1 + 1/2 + 1/3 + 1/4 + 1/5

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* Write a program to generate Harmonic Series. Example : Input – 5 Output – 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.28 (Approximately) */ class HarmonicSeries{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); double […]

1 Comment

## Java program to demonstrate switch case

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 […]

## Java program to find whether no. is palindrome or not

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /* Write a program to find whether no. is palindrome or not. Example : Input – 12521 is a palindrome no. Input – 12345 is not a palindrome no. */ class Palindrome{ public static void […]

## Java program to find whether given no. is Armstrong or not

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /*Write a program to find whether given no. is Armstrong or not. Example : Input – 153 Output – 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public […]

## Java program to generate a invert Triangle 4444 333 22 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /* Write a program to Display Invert Triangle. Example: Input – 5 Output : 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 */ class InvertTriangle{ public […]

## Java program to Find whether number is Prime or Not

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class PrimeNo{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int flag=0; for(int i=2;i<num;i++){ if(num%i==0) { System.out.println(num+" is not a Prime Number"); flag = 1; break; } } if(flag==0) System.out.println(num+" is a Prime Number"); } }

## Java program to generate a Triangle 1 22 333 444

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /*Write a program to generate a Triangle. eg: 1 2 2 3 3 3 4 4 4 4 and so on as per user given number */ class Triangle{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); […]

## Java program to convert given no. of days into months and days

1 2 3 4 5 6 7 8 9 10 11 12 13 /* Write a program to convert given no. of days into months and days. (Assume that each month is of 30 days) Example : Input – 69 Output – 69 days = 2 Month and 9 days */ class DayMonthDemo{ public static […]