Showing posts with label Java Number Programs. Show all posts
Showing posts with label Java Number Programs. Show all posts

Sunday, April 28, 2024

Program To Check Neon number Using BlueJ

What is neon number:


A neon number is that where sum of digits of square of the number is equal to the number.
For example if the input number is 9, it's square is 9*9 = 81 and sum of the digits is 9. 9 is a neon number


Java Program to check neon number


Download eBook on BlueJ 
import java.io.*;
class Neon
{
int n,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
 System.out.println("Enter the number:");
 n=Integer.parseInt(br.readLine());
 sq=n*n;
 while(sq>0)
{
 sum=sum+sq%10;
 sq=sq/10;
}
if(n==sum)
 System.out.println(n+ " is a neon number");
else
 System.out.println(n+ " is not a neon number");
}
public static void main(String args[])throws Exception
{
 Neon ob=new Neon();
ob.showNeon();
}
}

BlueJ Program On Neon Numbers Between 1 And 500

import java.io.*;
class Neon
{
int i,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
for(i=1;i<=500;i++)
{
sum=0;
 sq=i*i;
 while(sq>=1)
{
 sum=sum+sq%10;
 sq=sq/10;
}
if(i==sum)
 System.out.println(i+ " is a neon number");
}
}
public static void main(String args[])throws Exception
{
 Neon ob=new Neon();
ob.showNeon();
}
}

Related Post: BlueJ Programs on Number



BlueJ Program On Magic Number Checking


Magic numbers are those numbers where sum of the digits when converted into a single digit becomes 1.

Examples of some of the magic numbers are 100, 37, 55, 127 
100 while converted in to single digit becomes 1+0+0=1
37 while converted in to single digit becomes 3+7 = 10 = 1+0=1


import java.io.*;
class Max
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a;
int sum;
public void show()throws Exception
{
System.out.println("Enter the number:");
a=Integer.parseInt(br.readLine());
while(true)
{
sum=0;
if(a<10)
break;
while(a>0)
{
 sum=sum+a%10;
 a=a/10;
}
a=sum;
sum=0;
}
if(a==1)
System.out.println("The number is a magic number.");
else
System.out.println("The number is not a magic number.");

}
public static void main(String args[])throws Exception
{
 Max ob=new Max();
 ob.show();
}
}

Related Post: BlueJ Programs on Number

Download eBook on BlueJ 

Sample output:

Enter the number:
127
The number is a magic number.

Enter the number:
34
The number is not a magic number.


Display Automorphic Numbers From 1 To Any Specific Range


This is a BlueJ program which will take the upper range and will display all the automorphic numbers starting from 1 to the specific number.

import java.io.*;
class AutoM
{
 int x,i,n,no,sqn,revNum=0,digit=0;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void getNumber() throws Exception
 {
 System.out.println("Enter the upper range:");
 x=Integer.parseInt(br.readLine());
 for(int j=1;j<=x;j++)
 {
   n=j;
   digit=0;
   revNum=0;
 no=n;
do
{
   digit++;
  no=no/10;
 } while(no!=0);

 sqn=n*n;
 showR();
 }
 }
 public void showR()
 {
do
  {
   revNum=revNum*10+sqn%10;
   sqn=sqn/10;
   digit--;
   if(digit==0)
   break;
   }  while(true);

   revNum=revNumerse(revNum);
   if(n==revNum)
   System.out.println(n+" is an Automorphic number");
  }
 private int revNumerse(int n)
  {
   int r=0;
   while(n!=0)
   {
    r=r*10+n%10;
    n=n/10;
    }
    return r;
   }
   public static void main(String args[])throws Exception
   {
    AutoM obj=new AutoM();
    obj.getNumber();
    }
   }

Related Post: BlueJ Programs on Number

Saturday, April 27, 2024

Twist Number Program Using BlueJ

BlueJ Program on Twist Number checking. In this BlueJ program, the consecutive digits in a number will exchange their positions. If the number has odd number of digits then the last digit would remain the same

Example: Enter the Number: 123456
Original : 123456
Modified : 214365
(The above number has 06 Digits)


Enter the Number: 123
Original : 123
Modified : 213
(The above number has 03 Digits)


 import java.io.*;
class Twist
{
int n,n1;
int i,len;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take() throws Exception
{
System.out.print("\nEnter the Number:");
n=Integer.parseInt(br.readLine());
}
int countDigits(int m)
{
 int c=0;
for(int i=m;i> 0;i=i/10)
c++;
return c;
}
public void show()
{
 System.out.println("Original Number:"+n);
 System.out.println("Modified Number:"+n1);
}
public void exchange()
{
 len=countDigits(n);
System.out.println("Length="+len);
if(len%2!=0)
 n1=n;
else
{
for(int i=n;i> 0;i=i/100)
 n1=n1*100+i%100;
n1=rev(n1);
}
}
private int rev(int x)
{
 int r=0;
for(int i=x;i> 0;i=i/10)
r=r*10+i%10;
return r;
}
 public static void main(String args[]) throws Exception
{
Twist ob=new Twist();
ob.take();
ob.exchange();
ob.show();
 }
}

Related Post: BlueJ Programs on Number

Friday, December 8, 2023

Java Program To Check Boring Number

  Write a program in java to accept a number from user and check whether the number us a boring number or not.

Boring number is a positive number having all the digits at even position in the number as even and the digits at odd position odd

 

import java.util.*;
class BoringNumber
{
int n,rev,f;
Scanner sc=new Scanner(System.in);
public void take()
{
   System.out.print("\nEnter The Number:");
   n=sc.nextInt();
   display();
}
private void display()
{
   rev=0;
   f=1;
    System.out.print("\nEntered Number is:"+n);
   while(n>0)
   {
        rev=rev*10+n%10;
        n=n/10;
   }
   while(rev>0)
   {
       int d=rev%10;
       if(f%2!=d%2)
       break;
       rev=rev/10;
       f++;
   }
   if(rev>0)
   System.out.print("\nEntered Number is not a boring number");
   else
   System.out.print("\nEntered Number is a boring number");
}
public static void main(String args[])
{
BoringNumber ob=new BoringNumber();
ob.take();
}
}         


Sample Input Output


Enter The Number:1234
Entered Number is:1234
Entered Number is a boring number

Enter The Number:1321
Entered Number is:1321
Entered Number is not a boring number

Saturday, September 30, 2023

List Of BlueJ Number Programs For ICSE And ISC Students


Programs on Numbers using Java language for ICSE and ISC students are posted here. The programs can be executed on BlueJ or any other editors. Here you will get links to number of programs along with explanation. Hope it will help students.



To view the programs, click on the links






Keith Number











A Prime-Adam integer is a positive integer (without leading zeros) which is prime as well as an Adam number.

Prime number: A number which has only two factors, i,e 1 and the number itself.
Example: 2,3,5,7 etc

Adam number: The square of a number and the square of it's reverse are reverse to each other.

Example: If n=13 and reverse of 'n'=31 then square of 13 = 169 and square of 31 is 961 which is reverse of 169.

Thus 13 is an Adam number



Pythagorean Triplets


A number is called Smith Number if sum of the digits of the number is equal to the sum of the digits of the prime factors of the number are equal.

Sample Input: 666
Sum of the digits: 6 + 6 + 6 = 18
Prime factors are: 2, 3, 3, 37
Sum of the digits of the prime factors: 2 + 3 + 3 + (3 + 7) = 18
Thus, 666 is a Smith Number. 



Twist Number




Unusual number : In Mathematics, an unusual number is a natural  number whose greatest prime factor is strictly greater than square  root of n.

The first few unusual numbers are – 
 
2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 20, 21, 22, 23, 26, 28, 29, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 51



Ugly numbers are positive numbers whose only prime factors are 2, 3 or 5. First 10 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12. By convention, 1 is included.

Test Date:Input an integer number: 235
Output : It is not an ugly number.

Weak Arm Number




Tuesday, December 6, 2022

BlueJ Program On Keith Number

 What is Keith Number and How to Check


Keith Number: Let's check the number 742 is a Keith number or not.

First, we will separate each digit, as 7, 4, 2

To find the next term of the above-created series, we add these digits (i.e. 7+4+2), and the resultant (13) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13

To find the next term of the above series, we add the last three terms (i.e. 13+2+4), and the resultant (19) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19

To find the next term of the above series, we add the last three terms (i.e. 19+13+2), and the resultant (34) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34

To find the next term of the above series, we add the last three terms (i.e. 34+19+13), and the resultant (66) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66

To find the next term of the above series, we add the last three terms (i.e. 66+34+19), and the resultant (119) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119

To find the next term of the above series, we add the last three terms (i.e. 119+66+34), and the resultant (219) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219

To find the next term of the above series, we add the last three terms (i.e. 219+119+66), and the resultant (404) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219, 404

To find the next term of the above series, we add the last three terms (i.e. 404+219+119), and the resultant (742) that we get becomes the next term of the series.

Now, the series becomes, 7, 4, 2, 13, 19, 34, 66, 119, 219, 404, 742

As 742 is present in the series, 742 is a Keith Number.


Program On Keith Number

import java.util.*;
public class Keith
{
    int i,arr[],n,c=0;
    Scanner sc=new Scanner(System.in);
    void take()
    {
        int sum=0;
        System.out.print("\nEnter the number:");
        n=sc.nextInt();
        for(i=n;i>0;i=i/10)
        c++;
        arr=new int[c];
        int n1=c;
        for( i=n;i>0;i=i/10)
        arr[--n1]=i%10;
        System.out.print("\nSeries is: ");
        for(i=0;i<c;i++)
        {
        System.out.print(" "+arr[i]);
        if(n==arr[i])
        System.out.print(n + " is Keith Number");
        }
        while(true)
        {
            sum=0;        
        for(i=0;i<c;i++)
        {
            sum+=arr[i];             
        }
        System.out.print(" "+sum);
        if(n==sum)
        {
            System.out.print("\n"+ n + " is a Keith Number");
            break;
        }
        else if(n<sum)
        {
            System.out.print("\n"+ n + " is not a Keith Number");
            break;
        }
        else
        {
            for(i=0;i<c-1;i++)
            {
              arr[i]=arr[i+1];  
            }
            arr[i]=sum;
        }        
    }
    }
public static void main(String[] args) {
Keith ob=new Keith();
ob.take();
}
}


Other Programs On Numbers: CLICK HERE

Tuesday, March 29, 2022

BlueJ Program For Checking Unusual Number

 Check if a number is an Unusual Number or not Given a positive integer N. The task is to check if N is an unusual number or not. Print ‘YES’ if M is an unusual number else print ‘NO’.

Unusual number : In Mathematics, an unusual number is a natural  number whose greatest prime factor is strictly greater than square  root of n.

The first few unusual numbers are – 
 
2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 20, 21, 22, 23, 26, 28, 29, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 51
 
 import java.io.*;
class Str3
{
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    void take() throws Exception
    {
       int p,i,n;
       System.out.print("\nEnter any number: ");
       n=Integer.parseInt(br.readLine());
                  
       for(i=n;i>=2;i--)
       {
           if(n%i==0 && prime(i))
           break;          
        }
        p=i;        
        if(p>(int)Math.sqrt(n))
        System.out.println("It is unusual number");
       else
       System.out.println("It is not an unusual number");
    }
   
    private boolean prime(int n)
{
     int i;
     for(i=2;i<n;i++)
     {
         if(n%i==0)
         break;
        }
       if(i==n)
       return true;
       else
       return false;
    }
    public static void main(String args[])throws Exception
    {
        Str3 ob=new Str3();
        ob.take();
    }
}       
  
Other Programs On Numbers: CLICK HERE

Tuesday, March 15, 2022

Mystery Number Checking Using BlueJ Program

A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other.

Examples:

Input : n = 121 

Output : 29 92

Input : n = 22 

Output : 11 11


import java.util.*;
class Str3
{
   Scanner sc=new Scanner(System.in);
    void main()
    {
       int a,b,i,n;
       System.out.print("\nEnter any number: ");
       n=sc.nextInt();
       b=n-1;       
           
       for(i=1;i<=n/2;i++)
       {
           if(i==rev(b))
           break;
           b--;
        }
        if(i<=n/2)        
        System.out.println("Mystery Number");   
          else
        System.out.println("Not Mystery Number");
    }
   
private int rev(int n)
{
     int r=0;
     while(n>0)
     {
         r=r*10+n%10;
         n=n/10;
        }
        return r;
    }
    public static void main(String args[])
    {
        Str3 ob=new Str3();
        ob.main();
    }
}       

  Other Programs On Numbers: CLICK HERE

BlueJ Program To Print Fascinating Numbers

   Fascinating Numbers : Some numbers of 3 digits or more exhibit a very interesting property. The property is such that, when the number is multiplied by 2 and 3, and both these products are concatenated with the original number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes.
  Some examples of fascinating Numbers are: 192, 219, 273, 327, 1902, 1920, 2019 etc.


 import java.util.*;
class Str3
{
   Scanner sc=new Scanner(System.in);
    void main()
    {
       int a,b,i,n;
       System.out.print("\nEnter any number: ");
       n=sc.nextInt();
       a=n*3;
       b=n*2;
       String s0=Integer.toString(n);
       String s1=Integer.toString(a);
       String s2=Integer.toString(b);
       String s=s0+s1+s2;
       if(s.length()!=9)
       {
           System.out.println("Not a fascinating no.");
           System.exit(0);
       }
       int c[]=new int[10];
       for(i=0;i<9;i++)
       {
           int ch=s.charAt(i);
           int x=Character.getNumericValue(ch);
           c[x]++;
       }
       for(i=1;i<9;i++)
       {
           if(c[i]!=1)
           break;
       }
       if(i==9)
       System.out.println("Fascinating no.");
       else
       System.out.println("Not a fascinating no.");
    }
    public static void main(String args[])
    {
        Str3 ob=new Str3();
        ob.main();
    }
}       
  
Other Programs On Numbers: CLICK HERE

BlueJ Program To Print Lucky Numbers


  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, 26, 27, 28, 29,
Removing every second number produces the sequence
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29„ 
Removing every third number from the above sequence produces
1, 3, 7, 9, 13, 15, 19, 21, 25, 27, 
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 natural
 number N where N<=50.
SAMPLE
INPUT N = 10
1 2 3 4 5 6 7 8 9 
1  3  5  7  9 
1  3    7  9 
OUTPUT : THE LUCKY NUMBERS LESS THAN 10 ARE : 1 3 7
INPUT : N=25
 OUTPUT : TICE LUCKY NUMBERS LESS THAN 25 ARE 1 3 7 13 19

 import java.io.*;
class Str3
{
     int p,x,i,n,b,no;
     int arr[];
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    void take() throws Exception
    {      
       while(true)
       {
       System.out.print("\nEnter the range: ");
       n=Integer.parseInt(br.readLine());
       if(n<=50)
       break;
    }
    no=n;
    arr=new int[n];
    for(i=0;i<n-1;i++)
    arr[i]=i+1;
    arr[i]=-1;
    /* 'p' becomes 2,3,4,..... so that we can eliminate 2nd, 3rd, 4th position elements */
         p=2;
         while(p<=n)
         {
            x=0;
            b=0; 
       for(i=0;i<no;i++)
       {
            if(arr[i]==-1)
            break;
            b++;
            if(b%p!=0)
           {
           arr[x++]=arr[i];          
        }        
        }
       /* at the end we set -1 to denote end of elements are removal of specific location values */
        arr[x]=-1;        
        p++;
        n=b;        
    }   
    System.out.print("\nLucky Numbers as follows: ");
     for(i=0;i<no;i++)
     {     
         if(arr[i]==-1)
         break;
         System.out.print(" "+arr[i]);
        }
    }
    public static void main(String args[])throws Exception
    {
        Str3 ob=new Str3();
        ob.take();
    }
}       
  
Other Programs On Numbers: CLICK HERE

Sunday, January 30, 2022

Smith Number Checking Using BlueJ

 Write a program in Java to enter a number and check whether it is a Smith number or not.
Sample Input: 666
Sum of the digits: 6 + 6 + 6 = 18
Prime factors are: 2, 3, 3, 37
Sum of the digits of the prime factors: 2 + 3 + 3 + (3 + 7) = 18
Thus, 666 is a Smith Number. 

import java.util.*;
class A
{
     Scanner sc=new Scanner(System.in);
     int n,n1,digitSum, factorSum,i;     
     void show()
     {
digitSum=0;
factorSum=0;
System.out.print("\nEnter Number: ");
n=sc.nextInt();
for(i=n;i>0;i=i/10)
{
    n1=i%10;
digitSum=digitSum+n1;
}
for(i=2;i<=n;i++)
{
   
 if(isPrime(i) && n%i==0 && i<10)
 {
 factorSum=factorSum+i;
 
 n=n/i;
 i--;
 
}
 else if(isPrime(i) && n%i==0)
 {
     factorSum=factorSum+digits(i);
     n=n/i;
 i--;
}
}
   
if(digitSum==factorSum)
System.out.print("\nSmith Number...");
else
System.out.print("\nNot a Smith Number...");
}
private int digits(int n)
{
    int i,s=0;
    for(i=n;i>0;i=i/10)
    s=s+i%10;
 
    return s;
}
private boolean isPrime(int n)
{
     int i;
     for(i=2;i<n;i++)
     {
          if(n%i==0)
          break;
        }
        if(i==n)
        return true;
        else
        return false;
    }
}
  
Other Programs On Numbers: CLICK HERE

BlueJ Program On Bouncy Number

 A number is said to Bouncy number if the digits of the number are unsorted.
For example,
22344 - It is not a Bouncy number because the digits are sorted in ascending order.
774410 - It is not a Bouncy number because the digits are sorted in descending order.
155349 - It is a Bouncy number because the digits are unsorted.
A number below 100 can never be a Bouncy number.
Write a program in java to accept a number. Check and display whether it is a Bouncy number or not.

import java.util.*;
class A
{
     Scanner sc=new Scanner(System.in);
     int n,i,greater_less,d;     
     void show()
     {
greater_less=0;
System.out.print("\nEnter Number: ");
n=sc.nextInt();
d=n%10;
n=n/10;
if(d>n%10)
greater_less=1;
 
for(i=n;i>0;i=i/10)
{
    if(i%10<d && greater_less==1);// ascending
    
    else if(i%10>d && greater_less==0);
    else
    break;
    d=i%10;
}
   if( i==0)
   System.out.print("\nNot Bouncy Number....");
   else
   System.out.print("\nBouncy Number....");
}
}

Other Programs On Numbers: CLICK HERE

Saturday, July 3, 2021

Decimal To Octal Conversion Using Recursive Function


A class DeciOct has been defined to convert a decimal number into its equivalent octal number. Some of the members of the class are given below:

Class name: DeciOct
Data members/instance variables:
n: stores the decimal number
oct: stores the octal equivalent number

Member functions:

DeciOct(): constructor to initialize the data members
n = 0, oct = 0.

void getnum(int nn): assign nn to n

void deci_oct(): calculates the octal equivalent of ‘n’ and stores it in oct using the recursive technique

void show(): displays the decimal number ‘n’, calls the function deci_oct() and displays its octal equivalent.

(a) Specify the class DeciOct, giving details of the constructor( ), void getnum(int), void deci_oct( ) and void show(). Also define a main() function to create an object and call the functions accordingly to enable the task.

 
import java.util.*;
class DeciOct
{
    int n;
    String oct;
    DeciOct()
    {
        n=0;
        oct="";
    }
    private void getnum(int nn)
    {
        n=nn;
    }
    void deci_oct(int a)
    {
        String s="";
        int d=a/8;
        int r=a%8;
        if(r==0)
        return;
        oct=r+oct;
        deci_oct(d);
    }
    void show()
    {
        System.out.println("The Original Number :"+n);
        deci_oct(n);
        System.out.println("Its Octal Equivalent :"+oct);
    }
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the Number :");
        int num=sc.nextInt();
        DeciOct ob=new DeciOct();
        ob.getnum(num);
        ob.show();
    }
}

Other Programs On Numbers: CLICK HERE

Evil Number Program Using BlueJ

 

An Evil number is a positive whole number which has even number of 1’s in its binary equivalent.
Example: Binary equivalent of 9 is 1001, which contains even number of 1’s.
 Thus, 9 is an Evil Number.

A few Evil numbers are 3, 5, 6, 9....

Design a program to accept a positive whole number ‘N’ where N>2 and N<100. Find the binary
equivalent of the number and count the number of 1s in it and display whether it is an Evil number or
not with an appropriate message.

Test your program with the following data and some random data:

Example 1:
INPUT: N = 15
BINARY EQUIVALENT: 1111
NUMBER OF 1’s: 4
OUTPUT: EVIL NUMBER

Example 2:
INPUT: N = 26
BINARY EQUIVALENT: 11010
NUMBER OF 1’s: 3
OUTPUT: NOT AN EVIL NUMBER

Example 3:
INPUT: N = 145
OUTPUT: NUMBER OUT OF RANGE

import java.util.*;
class EvilNumber
{
    void take(int n)
    {       
        String s="";
        String s1="";
        int c=0,t=0;
        while(n>0)
        {
            int r=n%2;
            s=r+s;
            n=n/2;
        }
        t=Integer.parseInt(s);
        while(t!=0)
        {
            int r=t%10;
            if(r==1)
            c++;
            t=t/10;
        }
        if(c%2==0)
        {
            System.out.println("The original number is "+n);
            System.out.println("Its binary equivalent is "+s);
            System.out.println("It is an Evil Number");
        }
        else
        {
            System.out.println("The original number is "+n);
            System.out.println("Its binary equivalent is "+s);
            System.out.println("It is not a Evil Number");
        }
    }
public static void main(String args[])
{
 EvilNumber obj = new EvilNumber();
obj.take(23);
}
}

Other Programs On Numbers: CLICK HERE

Sunday, June 6, 2021

Program To Display Different Combinations Of Entered Values Using C Language

 In this program, five values will be entered by user and different combinations of the numbers will be displayed. In this post, the same program is done using C Language


#include<stdio.h>
void main ()
{
 int i,j,x;
      int arr[5];
    for(i=0;i< 5;i++)
{
         printf("Enter value:");
        scanf("%d",&arr[i]);
    }
    printf("The original valoues are \n");
    for(i=0;i< 5;i++)
    printf(" 5d "+arr[i]);
    printf("\nThe Combination are as follows \n");
    for(i=0;i < 5;i++)
     {
        x=i;
        for(j=0;j< 5;j++)
        {
            printf("%d  "+arr[x]);
            x++;
            if(x> 4)
            x=0;
        }
        printf("\n");
    }
getch();
    }

Thursday, April 29, 2021

BlueJ Program On Tech Number Checking


A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four digit tech numbers. 

Example :
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.


import java.util.*;
class A2
{
int a,b,c=0,digit=0,i;
Scanner sc=new Scanner(System.in);
void take()
{
    System.out.print("\nEnter the number: ");
    a=sc.nextInt();
    for(i=a;i>0;i=i/10)
    {
        digit++;
    }
     digit=digit/2;
     for(i=a;i>0;i=i/10)
     {
       c=c*10+i%10;
       digit--;
       if(digit==0)
       {
           i=i/10;
       break;
    }
    }
    b=i;
    c=rev(c);
        if(a==Math.pow((b+c),2))
    
    System.out.print(a + " is a tech number.");
    else
    System.out.print(a + " is not a tech number.");
}
 private int rev(int n)
 {
     int r=0;
     while(n>0)
     {
          r=r*10+n%10;
          n=n/10;
        }
        return r;
    }
    
 public static void main(String args[])
     {
        A2 ob=new A2();
        ob.take();
       
    }
}


Same program using another technique.

  
import java.util.*;
class A2
{
int b,c=0,digit;
String str1,s1,s2;
Scanner sc=new Scanner(System.in);
void take()
{
    System.out.print("\nEnter the number: ");
    str1=sc.nextLine();
    digit=str1.length();
     digit=digit/2;
     s2=str1.substring(digit);
     s1=str1.substring(0,digit);
     
    b=Integer.parseInt(s1);
    c=Integer.parseInt(s2);
    
    if(Integer.parseInt(str1)==Math.pow((b+c),2))
    
    System.out.print(str1 + " is a tech number.");
    else
    System.out.print(str1 + " is not a tech number.");
}
    
 public static void main(String args[])
     {
        A2 ob=new A2();
        ob.take();
       
    }
}

Other Programs On Numbers: CLICK HERE

Monday, January 18, 2021

BlueJ Program To Check A Number For Perfect Square Or Not


import java.util.*;
class Sw
{
   Scanner sc=new Scanner(System.in);
   int i,n,x;
   void show() 
   {
       System.out.println("\nEnter the number: ");
       n=sc.nextInt();
       for(i=2;i<n;i++)
       {
           if(n%i==0 && i==n/i)
           break;
        }
        if(i==n)
        System.out.println(n+ " is not a perfect square number");
        else
        System.out.println(n+ " is a perfect square number");            
    }

}


Other Programs On Numbers: CLICK HERE

Monday, January 4, 2021

Decimal To Binary And Hexadecimal Conversion

 

class Name: Number

 Member Variable: int n

 Member Methods:

 constructor: assigns 0 to n

 input (): accept value for n

 decttobin(): convert and display the binary equivalent of n

 dectohex(): convert and display the hexadecimal equivalent of n

 

 Write a menu driven program to perform the job

 1. decimal to binary

 2. decimal to hexadecimal     

 

import java.util.*;

class Number

{

int n;

Scanner sc=new Scanner(System.in);

Number()

{

     n=0;

}

void input()

{

    System.out.print("\nEnter the Number:");

    n=sc.nextInt();

    System.out.print("\nEnter 1 for Decimal to binary, 2 for decimal to hexa:");

    int c=sc.nextInt();

    switch(c)

    {

         case 1:

         decttobin();

         break;

         case 2:

         dectohex();

         break;

         default:

         System.out.print("\nWrong Choice:");

         System.exit(0);

        }

    }

    private void  decttobin()

    {

        String s="";

        int i;

        for(i=n;i>0;i=i/2)

        {

             s=s+i%2;

        }

        System.out.print("\nequivalent binary= ");

        for(i=s.length()-1;i>=0;i--)

        System.out.print(s.charAt(i));

    }

        private void  dectohex()

    {

        String s="";

        int i,d;

        for(i=n;i>0;i=i/16)

        {

             d=i%16;

             if(d<=9)

             s=s+d;

             else 

             s=s+ (char)(55+d);

             /* ASCII of A is 65, B is 66 and so on, so the remainder is added with 55 and the int value is

              converted into char to give the hexa digit               */

        }

        System.out.print("\nequivalent Hexadecimal= ");

        for(i=s.length()-1;i>=0;i--)

        System.out.print(s.charAt(i));

    }

public static void main(String args[])

{

     Number ob=new Number();

     ob.input();

    }

}


Other Programs On Numbers: CLICK HERE

Thursday, July 16, 2020

Java Program On Sum Product And Appending Numbers


Take 10 numbers and calculate their sum and product. Finally generate a number where product is appended with the sum.

e.g: Sum=123

product = 23

Final number = 12323

import java.util.*;

class Num1

{

 Int i, sum=0, product=1, n, num;

String s;

Scanner sc=new Scanner(System.in);

void take()

{

for(i=0;i<10;i++)

{

System.out.print(“\nEnter value:”);

n=sc.nextInt();

sum=sum+n;

product=product*n;

}

S=String.valueOf(sum)+ String.valueOf(product);

num=Integer.parseInt(s);

}

public static void main(String args[])

{

Num1 ob=new Num1();

ob.take ();

}

 }

Other Programs On Numbers: CLICK HERE

Subscribe via email

Enter your email address:

Delivered by FeedBurner