DXC Technology interview question

Program to perform in java