Java'da döngüler kullanılarak yıldızlar ile üçgen yapıyoruz.
*
***
*****
*******
*********
***********
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner klavye = new Scanner(System.in);
System.out.println("Bir Sayı Giriniz :");
int n = klavye.nextInt();
for (int i = 0; i <= n ; i++) {
for (int j = 0; j < (n - i); j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i + 1); k++) {
System.out.print("*");
}
System.out.println(" ");
}
}
}
Ödev
Java'da döngüler kullanarak yıldızlar ile elmas yapınız.
*
***
*****
*******
*********
*******
*****
***
*
Ödev
Submit your work to complete this lesson.
Join the project workspace to share your solution and receive feedback.
Lesson discussion
Swap insights and ask questions about Java101
Be the first to start the discussion
Ask a question or share your thoughts about this lesson.