coding challenge for all the pros use a circular array to create a circular representation for the n-bit number. The cyclic shift operations will change where the first bit starts in the number. The cyclic shift left shifts every bit to the left by one position and the leftmost bit moves cyclically to the vacated rightmost position. Similarly, the cyclic shift right shifts every bit to the right by one position and the rightmost bit moves cyclically to the vacated leftmost position. example: input (1 1 1 1 0 0 0 0) output (1 1 1 0 0 0 0 1 )
The Joker · Feb 6, 2015 1:28 PM · 18,678 views
Hey there, don't post your assignment here, do it yourself.
WizIT · Jul 18, 2015 6:44 PM
You would have get better help if you have stated "help" instead of challenge.
mero_naam_ho · Jul 19, 2015 4:37 AM
Try stackoverflow.com
Hydrogen Sulphide · Jul 19, 2015 4:48 AM
here is java version but other way around..output (1111000) next iteration: 0111100 next iteration:0011110 and so on import java.util.Scanner; /** * * @author wiwi */ public class JavaApplication15 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here System.out.println("Please enter your no"); Scanner myScanner = new Scanner(System.in); int number = myScanner.nextInt(); String numberString = ""; numberString = Integer.toString(number); int sizeOFstring = numberString.length(); char[] myArray = new char[sizeOFstring]; char[] tempArray = new char[sizeOFstring]; for (int i = 0; i < sizeOFstring; i++) { myArray[i] = numberString.charAt(i); tempArray[i] = numberString.charAt(i); } String choice = " "; int n = 0; while (n == 0) { //System.out.println("size of array" + myArray); System.out.println("Please press ('N') or ('n') to start cycle"); System.out.println("Please press any key to quit"); choice = myScanner.next(); if ((choice.equals("N")) || (choice.equals("n"))) { int j = 0; myArray[0] = tempArray[sizeOFstring - 1]; for (int i = 1; i < sizeOFstring; i++) { myArray[i] = tempArray[j]; j++; } for (int i = 0; i < sizeOFstring; i++) { tempArray[i] = myArray[i]; j++; } for (int i = 0; i < sizeOFstring; i++) { System.out.print(tempArray[i]); } System.out.println(); } else { System.out.println("Thank you"); n = 1; } } } } Last edited: 19-Jul-15 01:30 PM
wiwi · Jul 19, 2015 1:28 PM
kasto khatey magney ho yar..help chaiye ta help bhanda k ko laaj...thukka ni...teri soch ra jindagi.
herealone · Jul 19, 2015 1:41 PM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion