Skip to main content

Posts

NEAREST PRIME

Program 10: Nearest Prime Of A Number For Example User inputted 100 then 101 is nearest prime user inputs 102 then 103 and 101 are nearest primes. user inputs 97 then 97 itself is a prime. import java.io.*; class np //nearstprime   {        int posprime,negprime;         public void checkip(int n)              { int i,c=0;                for(i=2;i<n;i++)                 {                   if(n%i==0)                     {                        c++;                      }                   }             if(c==0)   ...

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++;         }       ...