Skip to main content

Posts

Showing posts from February, 2016

Decimal To Binary

AJ Java Programs Program 9: To Convert Decimal Number into its binary equivalent. For Example: 12 binary equivalent 1100 Syntax: import java.io.*; class dec_to_bin { public static void main(String args[])throws IOException {     int decimal;     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));     System.out.println("Enter a biary Number");     decimal=Integer.parseInt(br.readLine());     int binary=0;     int power=0;         //while(binary.length()>0)     while(decimal>0)     {         int temp = decimal%2;         binary+=temp*Math.pow(10, power++);         decimal=decimal/2;     }     System.out.println(binary); }} Tested Ok Program If You Don't Understand anything or want any program please write your request in Comment Section And Please Like ...

String Palindrome

AJ Java Programs Program 8: String Palindrome: A String is said to be palindrome if  it conveys same meaning when read from front or back Example  MADAM, DAD, MALAYALAM etc Syntax: import java.io.*; class str_palin {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         String s,rev="";         System.out.println("Enter a string to reverse It");         s=br.readLine();         s.trim();         int l=s.length();         for(int i=l-1;i>=0;i--)         {             rev=rev+s.charAt(i);         }             if(s.equals(rev))             System.out.println("It is s...

Piglatin

AJ Java Programs Program 7: Piglatin When in a word first character is moved to last and "ay" is added to it it becomes Piglatin Lets See how to do it. Syntax: import java.io.*; class  piglatin { public static void main(String args[])throws IOException {      char ch;    String word="",str="";    int i;    String s;    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));    System.out.println("Enter a String");    s=br.readLine();    s=s.trim();    s=" "+s+" ";    for(i=1;i<s.length();i++)    {        ch=s.charAt(i);        if(ch!=' ')        word+=ch;        else if(s.charAt(i-1)!=' ')        {            StringBuffer sb=new StringBuffer(word); ...

Remove Duplicate Characters

AJ Java Programs Program 6: Remove Duplicate Words From String Example:             Input: blogger output: bloger Syntax: import java.io.*; class RemoveDuplicateCharacter {     public static void main(String args[])throws IOException     {         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         System.out.print("Enter any word : ");         String s = br.readLine();         int l = s.length();         char ch;         String ans="";                   for(int i=0; i<l; i++)         {             ch = s.charAt(i);             if(ch!=' ')                 ans = ans + ch;   ...

Second largest element

AJ Java Programs Program 5: Finding Second Largest Element in Array Ex: {2,3,4,5,3,1} are elements then 4 is second largest element Syntax: Way 1: PreDefined import java.io.*; public class FindsecondLargest {     public static void main(String[] args) {         // intialize the array values         int arr[] = { 1, 23, 47, 81, 92, 52, 48, 56, 66, 65 };         int largest = arr[0];         int secondLargest = arr[0];         // check the condition         for (int i = 0; i < arr.length; i++) {             // this condition check for largest number             if (arr[i] > largest) {                 secondLargest = largest;                 largest = arr[i];         ...

Disarium Number

AJ Java Programs Program 4: Disarium Number A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example  135 is a DISARIUM (Workings 1 1 +3 2 +5 3  = 135, some other  DISARIUM  are 89, 175, 518 etc) Syntax: import java.io.*; class disarium {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,n1,n2,c=0,sum=0,d=0;         System.out.println("Enter a Num");         n=Integer.parseInt(br.readLine());         n2=n1=n;         while(n2!=0)         {             n2=n2/10;             c++;         }       ...

Automorphic Number

AJ Java Programs Program 3 : Automorphic Number     A Number is said to be Automorphic if its square contains digits same as number. For Example:-  25 is Automorphic Number Since its Square 625 contains the original number 25. Syntax import java.io.*; class automorphic {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,sq,c=1,d=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         sq=n*n;         int n1=n;         while(n!=0)         {             d=n%10;             c=c*10;             n=n/10;         ...

BINARY TO DECIMAL

AJ Java Programs Program 2: Write a program to Convert Binary Number into a Decimal Equivalent Example: 11101 = 29 Syntax: import java.io.*; class bintodec //binary to decimal { public static void main(String args[])throws IOException {     String binary;     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));     System.out.println("Enter a biary Number");     binary=br.readLine();     int decimal=0;     int power=0;       //while(binary.length()>0)     while(binary.length()>0)     {         int temp = Integer.parseInt(binary.charAt((binary.length())-1)+"");         decimal+=temp*Math.pow(2, power++);         binary=binary.substring(0,binary.length()-1);     }     System.out.println(decimal); } } Tested Ok Program If You Don't Understand anything or want ...

Evil Number

AJ Java Programs Program 1: Write a Java program to check whether the inputted number is an Evil Number or not. A Number is said to be an Evil Number when Binary Equivalent of the number contains Even Number of  1's For Example :  5 Binary equivalent 101 Thus It have  Even Number of 1s Syntax: /*  *  100 % working code.  */ import java.io.*; class evilnum {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,c,d=0,sum=0,x=0,a=0,b=0;         System.out.println("ENTER A DECIMAL NUMBER");         n=Integer.parseInt(br.readLine());         while(n!=0)         {             c=0;             d=n%2;         ...