Alright, So I'm learning method in Java, I have to call on a method 10 times to display ten different words (I already have the for loop to call on the method). I just can't figure out how to get it to have 10 different words. This is what I have so far. I hate asking for help so much, but I've been stumped for over a day now.
public static void tenWords(int display){
}
public static void main(String[] args) {
for(int i=0;i<10;i++){
tenWords(i);
}
}
just try that:
public class Main{
private static String[] words = new String[] {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
public static void tenWords(int display){
System.out.println(words[display]);
}
public static void main(String[] args) {
for(int i=0;i<10;i++){
tenWords(i);
}
}
}
ice
Not giving complete answers, as this looks like a homework // learning question?
From desirable to undesirable:
You could have an array or list of words, and return the "display"th item in the array or list?
You could also use a switch/case method and hardcode the words that correspond with the display number.
You could also use a big if/elseif/elsif format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With