Generation

generate functionThu, 19 Jan 2023

Consider a number N. Write a program to print the resultant number R, which is formed by considering the below given steps: Language Coding Step 1: Reverse the number N except the last d (where d= 1, initially) digits and increment d by 1. Step 2: Repeat Step 1 untill d is equal to the length of N. Step 3: Print the resulting number R after all the iterations, and it will have the same length as N. Read the input from STDIN and write the output to STDOUT. You should not write arbitrary strings while reading the input and while prin Constraints: The number of digits in N should be greater than 2. Input Format: A single line of input consists of a number N. Output Format: A single line of output consists of a resultant number R. Sample Input1: 4567 Sample Output1:

Scanner input = new Scanner(System.in); int number = input.nextInt(); String numberStr = Integer.toString(number); int count = 0; int len = numberStr.length(); while(count < len){ int end = number%10; int start = number/((int)Math.pow(10, len-1)); int base = number - start * (int)Math.pow(10, len-1); number = end * (int)Math.pow(10, len-1) + base/10; count++; } System.out.println(number);

Questions about programming?Chat with your personal AI assistant