+ 2
I didn’t fully understand the topic, or an error during verification?
if put ; The code works but not the way I would like. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for(int i=0; i<n; i++) ; <========here { System.out.println("Welcome"); } } }
2 ответов
+ 5
If you put the semicolon after the loop construct, then the block underneath will not be considered as the loop body, thus there will be only 1 line of "Welcome" printed on screen.
If the instruction was to print "Welcome" <n> number of times, then don't put the semicolon after the loop construct.
+ 1
thank you for your time. I understand