Java program to generate a invert Triangle 4444 333 22 1

Saturday, February 5th, 2011  »  Posted By  »  Total 0 Comment

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

Friday, February 4th, 2011  »  Posted By  »  Total 2 Comments

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

Friday, February 4th, 2011  »  Posted By  »  Total 2 Comments

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

Friday, February 4th, 2011  »  Posted By  »  Total 0 Comment

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

Friday, February 4th, 2011  »  Posted By  »  Total 0 Comment

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

Friday, February 4th, 2011  »  Posted By  »  Total 3 Comments

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

Friday, February 4th, 2011  »  Posted By  »  Total 0 Comment

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

Friday, February 4th, 2011  »  Posted By  »  Total 0 Comment

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

Friday, February 4th, 2011  »  Posted By  »  Total 4 Comments

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 */ class Fibonacci{ public static void main(String args[]){ int num [...]

Java program to Reverse the given number

Friday, February 4th, 2011  »  Posted By  »  Total 0 Comment

1 2 3 4 5 6 7 8 9 10 11 12 class Reverse{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); //take argument as command line int remainder, result=0; while(num>0){ remainder = num%10; result = result * 10 + remainder; num = num/10; } System.out.println("Reverse number is : "+result); } }

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup