Basic Programs

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 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 […]


Java program to Swap the values

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Swap{ public static void main(String args[]){ int num1 = Integer.parseInt(args[0]); int num2 = Integer.parseInt(args[1]); System.out.println("\n***Before Swapping***"); System.out.println("Number 1 : "+num1); System.out.println("Number 2 : "+num2); //Swap logic num1 = num1 + num2; num2 = num1 – num2; num1 = […]


Java program to Display Multiplication Table

1 2 3 4 5 6 7 8 9 10 11 12 class MultiplicationTable{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); System.out.println("*****MULTIPLICATION TABLE*****"); for(int i=1;i<=num;i++){ for(int j=1;j<=num;j++){ System.out.print(" "+i*j+" "); } System.out.print("\n"); } } }


Java program to Concatenate natural numbers up to given range

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 /* Write a program to Concatenate natural numbers up to given range using for Loop Example: Input – 5 Output – 1 2 3 4 5 */ class Join{ public static void main(String args[]){     int num = […]


Java program to find sum of all integers between 100 & 200 that are divisible by 7

1 2 3 4 5 6 7 8 9 10 11 12 /* Write a program to find sum of all integers greater than 100 and less than 200 that are divisible by 7 */ class SumOfDigit{ public static void main(String args[]){ int result=0; for(int i=100;i<=200;i++){ if(i%7==0) result+=i; } System.out.println("Output of Program is : "+result); […]


Java program to find Fibonacci series of a given number

Java program to find Fibonacci series of a given number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 /*Write a program to find Fibonacci series of a given no. Example : Input – 8 Output – 1 1 2 3 5 8 13 21 […]