مرحبا اريد ان اعرف كيف اطبع هذا
J
JO
JOR
JORD
JORDA
JORDAN
باستخدام ARRAY , و FOR
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char[] input = scanner.next().toCharArray();
scanner.close();
for (char letter : input) {
System.out.println(letter);
}
}
}
عفواً قرأت السؤال خطأ. هذ هو الحل الصحيح:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final String NEW_LINE = System.getProperty("line.separator");
System.out.print("Word: ");
final Scanner scanner = new Scanner(System.in);
final String input = scanner.nextLine();
scanner.close();
final int inputLength = input.length();
final StringBuilder builder = new StringBuilder(inputLength);
for (int i = 0; i < inputLength; i++) {
for (int j = 0; j <= i; j++) {
builder.append(input.charAt(j));
}
builder.append(NEW_LINE);
}
System.out.print(builder.toString());
}
}
التعليقات