-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSalyangoz.java
More file actions
33 lines (30 loc) · 1006 Bytes
/
Salyangoz.java
File metadata and controls
33 lines (30 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.company;
import java.util.Scanner;
public class Salyangoz {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("Sayı Giriniz: ");
int sayi = scanner.nextInt();
int neredeyiz = 1;
int[][] tablo = new int[sayi][sayi];
for(int satir = 0; satir < sayi; satir++){
if(satir%2 == 0){
for(int sutun = 0; sutun<sayi; sutun++){
tablo[satir][sutun] = neredeyiz;
neredeyiz++;
}
}else{
for(int sutun = sayi-1; sutun >= 0; sutun--){
tablo[satir][sutun] = neredeyiz;
neredeyiz++;
}
}
}
for(int satir = 0; satir<sayi; satir++){
for(int sutun = 0; sutun<sayi; sutun++){
System.out.print(tablo[satir][sutun]+" ");
}
System.out.println("");
}
}
}