Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Demirci Ayhan
Greenhorn
+ Follow
news
3
Posts
1
Threads
since Dec 26, 2014
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
Recent posts by Demirci Ayhan
Loop problem java exercice
Thanks to you all, i was finally able to do it, here is the code i used :
package Dessin; import java.util.Scanner; class Dessin { public static final char alphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println("\n"); int i = 0; System.out.print("lettre à utiliser : "); while (i < n) { System.out.print(alphabet[i] + " "); i++; } System.out.println("\n"); Dessin.runThis(n); } public static char defLettre(int j) { char result = alphabet[j]; return result; } public static void runThis(int n) { for (int l = 1; l <= 2 * n - 1; l++) { System.out.println("\n"); for (int c = 1; c <= 2 * n - 1; c++) { for (int j = 1; j <= 2 * n - 1; j++) { if (((l == j) || (c == j)) || (l == 2 * n - j) || (c == 2 * n - j)) { System.out.print(defLettre(j - 1)); break; } } } } } }
show more
10 years ago
Beginning Java
Loop problem java exercice
Oh sorry, here is the code :
public static final char alphabet[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; public static char defLettre(int j) { char result = alphabet[j]; return result; } public static void runThis(int n) { for (int l = 1; l <= 2 * n - 1; l++) { System.out.println("\n"); for (int c = 1; c <= 2 * n - 1; c++) { boolean match = false; for (int j = 1; j < 2 * n; j++) { if ((l == 1) || (l == 2 * n - j) || (c == 1) || (c == 2 * n - j)) { if (j == 1) { System.out.print('a'); } else { System.out.print(defLettre(j - 1)); } match = true; break; } } } } } }
show more
10 years ago
Beginning Java
Loop problem java exercice
Hello,
i've been trying to do this program for a couple of days :
this is what i have to get :
for n = 4
aaaaaaa
abbbbba
abcccba
abcdcba
abcccba
abbbbba
aaaaaaa
for n =5
aaaaaaaaa
abbbbbbba
abcccccba
abcdddcba
abcdedcba
abcdddcba
abcccccba
abbbbbbba
aaaaaaaaa
this is what i was able to get for n=4 :
aaaaaaa
afedcba
aeedcba
adddcba
accccba
abbbbba
aaaaaaa
here is a pastebin so you see a bit :
http://pastebin.com/qwbxkwaS
I can't see what my problem is
Thanks for your help
show more
10 years ago
Beginning Java