Gerair 10 numbers e moview o primeiro número paira o final 10 vezes

Eu tenho um código que gera 1 a 10 numbers:

for (int i = 0; i <=10; i++) { for (int j = 1; j <=10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } } 

Eu obtenho esse resultado:

 12345678910 2345678910 345678910 45678910 5678910 678910 78910 8910 910 10 

Mas, eu quero esse resultado:

 12345678910 23456789101 34567891012 45678910123 56789101234 67891012345 78910123456 89101234567 91012345678 10123456789 

Como posso obter meu código paira que ele mova o primeiro número paira o final da string?

9 Solutions collect form web for “Gerair 10 numbers e moview o primeiro número paira o final 10 vezes”

Tente este:

 for (int i = 0; i < 10; i++) { for (int j = i + 1; j <= i + 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1 > 10 ? respones1 % 10 : respones1)); } } } paira (int i = 0; i <10; i ++) { for (int i = 0; i < 10; i++) { for (int j = i + 1; j <= i + 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1 > 10 ? respones1 % 10 : respones1)); } } } } for (int i = 0; i < 10; i++) { for (int j = i + 1; j <= i + 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1 > 10 ? respones1 % 10 : respones1)); } } } } for (int i = 0; i < 10; i++) { for (int j = i + 1; j <= i + 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1 > 10 ? respones1 % 10 : respones1)); } } } 

Eu acredito que a melhor maneira de abordair isso seria usair um deque / queue, pois faz girair os numbers na seqüência alcançável em apenas duas operações.

 ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } { ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } } ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } { ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } { ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } } ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } builder.append ("\ n"); ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue for(int i = 1; i <= 10; ++i) // Fill queue with [1..10] { deque.addLast(i); } StringBuilder builder = new StringBuilder(); // A StringBuilder will be more efficient than string concatenation for(int i = 1; i <= 10; ++i) { for(int item : deque) // Append the queue contents to the string { builder.append(item); } builder.append("\n"); // New line int temp = deque.removeFirst(); // Take the first item from the deque deque.addLast(temp); // And append it to the end of the deque } 

Aqui está uma solução dinâmica que funciona paira qualquer range de numbers, onde min é menor do que o máximo.

  int min = 1; int max = 10; int count = max - min; StringBuilder sb = new StringBuilder(); for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { sb.append(String.valueOf(((j + i) % (count + 1)) + min)); } sb.append("\n"); } System.out.println(sb.toString()); }  int min = 1; int max = 10; int count = max - min; StringBuilder sb = new StringBuilder(); for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { sb.append(String.valueOf(((j + i) % (count + 1)) + min)); } sb.append("\n"); } System.out.println(sb.toString()); }  int min = 1; int max = 10; int count = max - min; StringBuilder sb = new StringBuilder(); for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { sb.append(String.valueOf(((j + i) % (count + 1)) + min)); } sb.append("\n"); } System.out.println(sb.toString()); 

Isso deve:

 for (int i = 0; i < 10; i++){ int res = i + 1; for (int j = 1; j <= 10; j++){ text.append(String.valueOf(res)); if (res == 10) res = 0; res++; } } } for (int i = 0; i < 10; i++){ int res = i + 1; for (int j = 1; j <= 10; j++){ text.append(String.valueOf(res)); if (res == 10) res = 0; res++; } } 

Experimente este código

 StringBuilder text = new StringBuilder(); StringBuilder text1 = new StringBuilder(); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } text1.append(String.valueOf(i)); if (i > 0) { text.append(text1); } text.append(" "); } System.out.println(text.toString()); } StringBuilder text = new StringBuilder(); StringBuilder text1 = new StringBuilder(); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } text1.append(String.valueOf(i)); if (i > 0) { text.append(text1); } text.append(" "); } System.out.println(text.toString()); } StringBuilder text = new StringBuilder(); StringBuilder text1 = new StringBuilder(); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } text1.append(String.valueOf(i)); if (i > 0) { text.append(text1); } text.append(" "); } System.out.println(text.toString()); } StringBuilder text = new StringBuilder(); StringBuilder text1 = new StringBuilder(); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } text1.append(String.valueOf(i)); if (i > 0) { text.append(text1); } text.append(" "); } System.out.println(text.toString()); } StringBuilder text = new StringBuilder(); StringBuilder text1 = new StringBuilder(); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= 10; j++) { int respones = i; int respones1 = j; if (respones1 > respones) { text.append(String.valueOf(respones1)); } } text1.append(String.valueOf(i)); if (i > 0) { text.append(text1); } text.append(" "); } System.out.println(text.toString()); 

tente isso

 StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } int count = 0; StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } } StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } count ++; StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } temp ++; StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } } StringBuilder text=new StringBuilder(); int repeat=10; for (int index=1;index<=repeat;index++){ int count=0; int temp=index; while (count<repeat){ if(temp<=repeat){ text.append(temp); }else { temp=temp-repeat; text.append(temp); } count++; temp++; } text.append(" "); } 
 final int count = 10; for (int i = 1; i <= count; i++) { String str = ""; // Loop through count + i for (int j = i; j <= i + count -1; j++) { // If j is greater than count then just minus it from count final int currentValue = j <= count ? j : j-count; str = str + currentValue; } System.out.println(str); } } final int count = 10; for (int i = 1; i <= count; i++) { String str = ""; // Loop through count + i for (int j = i; j <= i + count -1; j++) { // If j is greater than count then just minus it from count final int currentValue = j <= count ? j : j-count; str = str + currentValue; } System.out.println(str); } 

Também pode ser feito como abaixo:

 int no = 1; int n = 10; StringBuilder sb; for(int i=1;i<=n;i++){ sb = new StringBuilder(); int cnt = 1; no = i; while(cnt<=n){ if(no<=n){ sb.append(no).append(" "); no++; cnt++; }else{ no=(no-n); sb.append(no).append(" "); no++; cnt++; } } System.out.println(sb.toString()); } } int no = 1; int n = 10; StringBuilder sb; for(int i=1;i<=n;i++){ sb = new StringBuilder(); int cnt = 1; no = i; while(cnt<=n){ if(no<=n){ sb.append(no).append(" "); no++; cnt++; }else{ no=(no-n); sb.append(no).append(" "); no++; cnt++; } } System.out.println(sb.toString()); } } int no = 1; int n = 10; StringBuilder sb; for(int i=1;i<=n;i++){ sb = new StringBuilder(); int cnt = 1; no = i; while(cnt<=n){ if(no<=n){ sb.append(no).append(" "); no++; cnt++; }else{ no=(no-n); sb.append(no).append(" "); no++; cnt++; } } System.out.println(sb.toString()); } 

Isso é c #

 public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } } public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } } public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } } public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } { public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } } public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } } public static void OneToTen() { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 10; i++) { sb.Cleair(); for (int j = i; j <= 10; j++) { sb.Append(j); } for (int j = 1; j < i; j++) { sb.Append(j); } Debug.WriteLine(sb.ToString()); } //second solution Debug.WriteLine(""); for (int i = 0; i < 10; i++) { sb.Cleair(); for (int j = 0; j < 10; j++) { sb.Append(((i+j)%10) + 1); } Debug.WriteLine(sb.ToString()); } Debug.WriteLine(""); } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.