Skip to main content

Posts

Showing posts from October, 2016

SMITH NUMBER

PROGRAM: SMITH NUMBER A   Smith number  is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 58, 85, 94, 121 ……………….. For Example 58=> 5+8=13 2+(2+9) of 29 =13 Since sum of digits=sum of digits of prime factors 58 is a SMITH NUMBER SYNTAX: import java.io.*; class smith_no { static int sum,sum1;     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int c=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         int n1=n;         while(n1!=0){         int d=n1%10;         sum1+=d;         n1=n1/10;}         for(int i=2;i<n;i++)         {             if(n%i==0)             {                 for(int j=2;j<i;j++)                 {                     if(i

KAPREKAR NUMBER

PROGRAM : KAPREKAR NUMBER A  Kaprekar number    is a  non-negative   integer , the representation of whose square  can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 45 2  = 2025 and 20+25 = 45. And if second splitted part have only 0s then it is not kaprekar number for example 100*100=10000 splitted part is 10+000 thus second part have 0s only Some Examples are: 999 999*999=998001=>998+001=999 1, 9, 45, 55, 99, 297, 703, 999, 2223, 2728, 4879, 4950, 5050, 5292, 7272, 7777, 9999, 17344, 22222, 38962, 77778, 82656, 95121, 99999,  142857 , 148149, 181819, 187110  are some examples of Kaprekar Number SYNTAX import java.io.*; class kaprekar {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int d=0,c=0;int n1;         System.out.println("ENTER A NUMBER");         n=Integer.parseInt(

REVERSING A STRING USING RECURSION

PROGRAM: REVERSING A STRING USING RECURSION Sample input: Java is robust output:            tsubor si avaJ SYNTAX import java.io.*; public class rev_str_rec { static String s,n="";     public static void main(String args[])throws IOException{     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));     System.out.println("ENTER A STRING TO REVERSE");     s=br.readLine();     int l=s.length();     reverse(l-1); } public static void reverse(int l) {if(l>-1)     {         n+=s.charAt(l);         l--;         reverse(l); } else System.out.println("REVERSED STRING: "+n); } }

UNIQUE NUMBER

PROGRAM : UNIQUE NUMBER A Number is Said to be unique if 1- it do not start with 0. 2- it do not have any repeating digit. for example: 0112 is not a unique no.                         1234 is a unique no.  SYNTAX: import java.io.*; class unique_num {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         String s;int val=0;         System.out.println("Enter a Number");         s=br.readLine();         if(s.charAt(0)=='0')         System.out.println("**** The Number is Not a Unique Number ****");         else         {             for(int i=0;i<s.length();i++)         {             for(int j=i+1;j<s.length();j++)             {                 if(s.charAt(i)==s.charAt(j)) //if any digits match, then we know it is not a Unique Number                 {                     val=1;                     break;              

MERSENNE NUMBER

PROGRAM : MERSENNE NUMBER A  number  is said to be  mersenne number  if it is one less than a power of 2. Example- 7 is a  mersenne number  as it is 2^3-1.Similarly 1023 is a  mersenne number  as it is 2^10-1. SYNTAX import java.io.*; class mersenne {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,m;         boolean flag=false;         System.out.println("Enter a number to check mersenne number");         n=Integer.parseInt(br.readLine());         m=n+1;         for(int i=0;i<=n;i++)         {             if((Math.pow(2,i)==m))             {                 flag=true;             }         }         if(flag==true)         {             System.out.println("The Number "+ (m-1)+" is Mersenne Number");         }         else         System.out.println("The Number "+ (m-1)+" is not a Mersenne Number&q

CIRCULAR/CYCLIC PRIME

PROGRAM : CYCLIC || CIRCULAR PRIME Question: A  Circular Prime  is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The process is repeated until the original number is reached again. A number is said to be prime if it has only two factors I and itself. Example: 131 311 113 Hence, 131 is a circular prime. Test your program with the sample data and some random data: Example 1 INPUT : N = 197 OUTPUT: 197 971 719 197 IS A CIRCULAR PRIME Example 2 INPUT : N = 1193 OUTPUT: 1193 1931 9311 3119 1193 IS A CIRCULAR PRIME SYNTAX: import java.io.*; class cyclic { static int c,c1,c2,count;//for counting no.of digits     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         System.out.println("Enter a Nu

MAGICAL/ MAGIC NUMBER USING RECURSION

PROGRAM :  MAGICAL NUMBER BY RECURSION This  program  checks if a  number  is a  Magic number  in  JAVA . A  number  is said to be a  Magic number  if the sum of its digits are calculated till a single digit is obtained by recursively adding the sum of its digits. If the single digit comes to be 1 then the  number  is a  magic number . Example: 10999 => 1+0+9+9+9=28=>2+8=>10=>1+0= 1                  199    =>1+9+9 =>19=> 1+9=>10=>1+0= 1 SYNTAX import java.io.*; class magic  {    static int c;     public static void main(String arsg[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int d=0;int m;         System.out.println("ENter a NUmber");         n=Integer.parseInt(br.readLine());         m=n;         while(n!=0)         {d=n%10;             n=n/10;             c++;         }         magical(m);              }     public static void magical(int x)

ARMSTRONG NUMBER

PROGRAM : ARMSTRONG NUMBER Armstrong Number in Java .  Armstrong Number in Java :  Armstrong number  is a number  that is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc. SYNTAX : import java.io.*; class armstrong  {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int n1;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         n1=n;int d=0,sum=0;         while(n!=0)         {             d=n%10;             sum+=Math.pow(d,3);             n=n/10;         }         if(sum==n1)         System.out.println("The Number is ARMSTRONG");         else         System.out.println("NO THE NUMBER IS NOT ARMSTRONG");     } }

EMIRP NUMBER

PROGRAM :  EMIRP NUMBER. An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31 are both prime numbers. Thus, 13 is an Emirp number. Design a class Emirp to check if a given number is Emirp number or not SYNTAX: import java.io.*; class emirp {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,rev=0,d=0,x=0,y=0;Boolean flag=false,flag1=false;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         for(int i=2;i<n;i++)         {             if(n%i==0)             x++;         }if(x==0)         flag=true;         while(n!=0)         {             d=n%10;             rev=rev*10+d;             n=n/10;         }         for(int j=2;j<=n;j++)         {             if(rev%j==0)             y++;         }         if(y==0)         flag1=true;         if((flag==t

Special Number

PROGRAM : SPECIAL NUMBER Check whether a number is Special Number in JAVA. This program checks whether a number is a Special Number or not. A number is said to be special number when the sum of factorial of its digits is equal to the number itself. Example-  145  is a Special Number as 1!+4!+ 5 != 145 SYNTAX: import java.io.*; class special_number {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         System.out.println("Enter a number");         int n=Integer.parseInt(br.readLine());         int n1=n;int d=0,sum=0,f=1;         while(n!=0)         {f=1;             d=n%10;             for(int i=1;i<=d;i++)             {f*=i;             }             sum+=f;             n=n/10;         }         if(sum==n1)         System.out.println("YES THE NUMBER IS  SPECIAL NUMBER");         else         System.out.println("NO THE  NUMBER IS N

LUCKY NUMBER

PROGRAM : LUCKY NUMBER QUESTION: Consider the sequence of natural numbers. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 …………………………………. Removing every second number produces the sequences 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 …………………………. Removing every third number produces the sequences 1, 3, 7, 9, 13, 15, 19, 21, 25 …………………………. This process continues indefinitely by removing the fourth, fifth…and so on, till after a fixed number of steps, certain natural numbers remain indefinitely. These are known as  Lucky Numbers . Write a program to generate and print lucky numbers less than a given number N. SAMPLE INPUT :   N = 10 OUTPUT :   The Lucky numbers less than 10 are:     1     3     7 SAMPLE INPUT :   N = 25 OUTPUT :   The Lucky numbers less than 25 are:     1     3     7     13     19 SYNTAX import java.io.*; class LuckyNumbers { public static void main(String args[])throws IOException { BufferedR

REQUESTED PROGRAM 1

PROGRAM:   REQUESTED  BY ANKUR ACHARYA. ISC 2016 QUESTION Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. The words are separated with a blank space, and are in uppercase. Perform the following: Find the number of words beginning and ending with a vowel. Place the words which begin and end with a vowel at the beginning, followed by the remaining words as they occur in the sentence. Test your program with the sample data and some random data: Example 1: INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE. OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 3 ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL. Example 2: INPUT: YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY. OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 2 A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY. Example 3: INPUT: LOOK BEFORE YOU LEAP. OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL: 0 LOOK B