Array-promo

Question

print reverse of  numbers in an array.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class ReverseNumbersInArray
{  
    
    public static void main(String[] args)
    {  
        /* Initialize array */  
        int [] arr;
       
        int n=0,i=0,temp=0,reversedInteger=0,remainder=0;
        Scanner sc = new Scanner(System.in);    
        
        System.out.println("Enter a number of elements in the array");   
        n = sc.nextInt(); 
        arr=new int[n];
        System.out.println("Enter numbers in array");
        
        for(i=0;i< n;i++)
        {
           arr[i]=sc.nextInt();
        }
        
       /* printing reverse numbers in an array */
        System.out.println("reverse numbers in an array");
        for(i=0;i< n;i++)
        {
            reversedInteger=0;
            temp= arr[i];
            /* reversed integer is stored in variable */
            while( temp != 0 )
            {
                remainder = temp % 10;
                reversedInteger = reversedInteger * 10 + remainder;
                temp /= 10;
            }
    
            System.out.print(reversedInteger+"    ");
        }
        
    }
}
				
			

Coding Store

10-minute Stress-Buster Games

Leave a Reply

Your email address will not be published. Required fields are marked *