Posts

Showing posts from January, 2022

Write a Java program to accept a positive number and repeatedly add all its digits until the result has only one digit.

Image
/* Write a Java program to accept a positive number and repeatedly add all its digits until the result has only one digit. */ import java.util.*; class Twelve { public static void main(String arg[]) { Scanner obj = new Scanner(System.in); int no; System.out.print("\nEnter any positive number :"); no = obj.nextInt(); if(no != 0) { while(no > 9) { int b = 0; while(no != 0) { b += no % 10; no /= 10; } no = b; } } System.out.println("sum : " + no); } }  More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to print numbers between 1 to 100 which are divisible by 3, 5 and by both.

Image
  /*  Write a Java program to print numbers between 1 to 100 which are divisible by 3, 5 and by both. Sample Output: Divided by 3: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57 , 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, Divided by 5: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, Divided by 3 & 5: 15, 30, 45, 60, 75, 90, */ class Eleven { public static void main(String arg[]) { int  a=0, b=0,c, d,e=0; int arr1[] = new int[50]; int arr2[] = new int[50]; for(int i=1 ; i<100 ; i++) { c = i % 3; d = i % 5; if(c == 0) { arr1[a] = i; a++; }     if(d == 0)     { arr2[b] = i; b++;     }     } System.out.print("\n Divisible by 3 :"); for(int j=0 ; j<a ; j++) { System.out.print(""+ arr1[j]+"," ); } System.out.print("\n\n Divisible by 5 : "); f...

Write a Java program to compute the number of trailing zeros in a factorial.

Image
 /* Write a Java program to compute the number of trailing zeros in a factorial. 7! = 5040, therefore the output should be 1 */ import java.util.*; class Ten { public static void main(String arg[]) { Scanner obj = new Scanner(System.in); int no , a=1 , b , c=0 , d=0; int arr[] = new int[20]; System.out.print("\nEnter number to find factorial \n and it's trailing zeros: "); no = obj.nextInt(); if(no != 0) { for(int i=no ; i>0 ; i--) { a = a * i; } System.out.println("\nFactoriyal is : " + a ); }  else { System.out.println("Enterd number is zero"); } while(a != 0) { b = a % 10; arr[c] = b; c++; a = a / 10; } for (int i=0 ; i<c ; i++)  { if(arr[i]==0) { d++; } else { break; } } System.out.println("number of trailing zeros is: " + d); } } More Information on our channel  Programmer Community please like...

Write a Java program to convert a decimal number to binary number.

Image
  /*  Write a Java program to convert a decimal number to binary number. Input Data: Input a Decimal Number : 5 Expected Output Binary number is: 101  */ import java.util.*; class Nine { public static void main(String arg[]) { Scanner obj = new Scanner(System.in); int i=0,x,no,y; System.out.print("\nEnter any decimal value to convert it into Binary: "); no = obj.nextInt(); int arr[] = new int[100]; if(no != 0) { do { x = no / 2; arr[i] = no % 2; no = x; i++; } while(no != 0); } else { System.out.println("Enterd number is Zero"); } System.out.print("\nBinary is : "); for(int z=i-1 ; z>=0 ;z--) { System.out.print ("" + arr[z]); } } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to check whether an given integer is a power of 4 or not.

Image
  /* Write a Java program to check whether an given integer is a power of 4 or not. Given num = 64, return true. Given num = 6, return false. */ import java.util.*; class Eight { public static void main( String arg[] ) { Scanner obj = new Scanner( System.in ); int a, x = 1; System.out.print("\nEnter any number to check\nnumber is power of 4 or not : "); a = obj.nextInt(); outer: if( a>4 ) { for (int i=1 ; i<=a ; i++ ) { x = x * 4; if(x == a) { System.out.println("\n\t => True <="); break outer; } else if( x > a ) { System.out.println("\n\t => False <="); break outer; } } } else { System.out.println("\n\t => False <="); break outer; } } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will c...

Write a Java program to multiply two given integers without using the multiply operator(*).

Image
 /* Write a Java program to multiply two given integers without using the multiply operator(*). */ import java.util.*; class Seven { public static void main( String arg[] ) { Scanner obj = new Scanner(System.in); int a, b, c=0; System.out.print("\nEnter number for A :"); a = obj.nextInt(); System.out.print("Enter number for B :"); b = obj.nextInt(); for(int i=1 ; i<=b ; i++) { c = c + a; } System.out.println("\nMultiplication is : " + c ); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to print the ascii value of a given character.

Image
  /* Write a Java program to print the ascii value of a given character. Expected Output The ASCII value of Z is :90 */ import java.util.*; class Six { public static void main(String arg[]) { Scanner obj = new Scanner( System.in ); char a; System.out.print("\nEnter any symbole or character : "); a = obj.next().charAt(0); int b = a; System.out.println("The ASCII value of " + a + " is => " + b ); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to convert seconds to hour, minute and seconds.

Image
  /* Write a Java program to convert seconds to hour, minute and seconds. Sample Output: Input seconds: 86399 23:59:59 */ import java.util.*; class Fifth { public static void main(String arg[]) { Scanner obj = new Scanner(System.in); int sec, hour, min, no; int x; System.out.print("\nEnter seconds : "); no = obj.nextInt(); x = no/ 60; hour = x / 60; min = x - (hour*60); sec = no - ((hour*60)*60) - (min * 60); System.out.println("\n Time : " + hour + ":" + min + ":" + sec ); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to find the numbers greater than the average of the numbers of a given array.

Image
  /*Write a Java program to find the numbers greater than the average of the numbers of a given array.*/ import java.util.*; class Fourth { public static void main(String arg[]) { Scanner obj=new Scanner(System.in); int[] arr = new int[5]; int sum = 0, ave; for(int i=0 ; i<5 ; i++) { System.out.print("Enter the number : "); arr[i] = obj.nextInt(); sum = sum + arr[i]; } ave = sum / 5; System.out.println("\nSum of enterd numbers : " + sum ); System.out.println("Average : "+ave); System.out.println("\nNumbers greater than everage :"); for(int i=0 ; i<5 ; i++) { if(arr[i] > ave) { System.out.println(" " + arr[i] ); } } } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to add two numbers without using any arithmetic operators. Given x = 10 and y = 12; result = 22

Image
 /*Write a Java program to add two numbers without using any arithmetic operators.  Given x = 10 and y = 12; result = 22*/ import java.util.*; class Third  { public static void main(String arg[]) { Scanner obj = new Scanner ( System.in ); int a, b, c; System.out.print("\nEnter value for A: "); a = obj.nextInt(); System.out.print("Enter value for B: "); b = obj.nextInt(); while(b!=0) { c = a & b; a = a^b; b=c<<1; } System.out.println("\nSum is : "+a); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.

Image
/*Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.*/ class Second { public static void main ( String arg[] ) { int a , b; a = 10; b = 5; System.out.println("A : "+ a +"\nB : "  + b ); System.out.println("Addition : " + ( a + b ) ); System.out.println("Multiplication : " + ( a * b ) ); System.out.println("Substaction : " + ( a - b ) ); System.out.println("Division :" + ( a / b ) ); System.out.println("Remainder : " + ( a % b ) ); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel

Write a Java program to print 'Hello World' on screen and then print your name on a separate line.

Image
  /* Write a Java program to print 'Hello World' on screen and then print your name on a separate line. */ class First { public static void main(String arg[]) { System.out.println("Hello World"); System.out.println("Programmer"); System.out.println("Community"); } } More Information on our channel  Programmer Community please like , share and subscribe to get notifications of new videos.... To understand this program video will coming soon  on   our you tube channel