Thursday, 14 January 2021


HAY THANK FOR VISIT'
Question:-write a program with a class name twist that accepts a number,N,that has even number of digits.
creat a new number N2 from N,such that each pair of digits from lest side are reserved. in casae N has odd numbers of digit N2=N

answer:-


import java.util.*;
class TWIST
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter the number ");
        int n=sc.nextInt();
        int t=n;int c=0;int i;int n1=0;
        while(t>0)
        {
            
            c=c+1;
            n1=n1*10+(t%10);
            t=t/10;
        }             
        int arr[]=new int[c];
        t=0;
        if(c%2==0)
        {
            for(i=0;i<c;i++)
            {
                arr[i]=n1%10;
                n1=n1/10;
            }
            for(i=0;i<(c/2);i=i+2)
            {
                t=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=t;
            }for(i=0;i<c;i++)
            {
                
            System.out.print(arr[i]);
        }
        }
        else
        {
            System.out.println(n);
        }
}
}

No comments:

Post a Comment

HAY THAKYOU FOE VISIT

Program(python):-Find duplicates in an array (Geeks for geek problem)

QUESTION:- Given an array  a  of size  N  which contains elements from  0  to  N-1 , you need to find all the elements occurring more than o...