… using for loops in Java. For example, hello would be printed five times.
Here is my code so far:
import java.util.Scanner;
class Words {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter one word of your choice");
String word = scan.nextLine();
System.out.println(word);
int length = word.length();
System.out.println(length);
for (length < word; length++) {
System.out.println(word);
}
}
}
We have to use the scanner package. Sorry if this is really basic but I’m just starting out and can’t find an answer anywhere!
You just need to write a loop which runs for 0 to the length of the word e.g. below: