Help | Sololearn: Learn to code for FREE!
+ 1


how can i print the results without printing out the last empty line

11th Nov 2021, 7:23 PM
John Delvin
John Delvin - avatar
8 Respostas
+ 7
John Delvin , (if we are talking about the exercice 17.2 in java tutorial) the spelling for 'welcome' has to be 'Welcome', all the rest is no problem. the "empty" line that is shown in the error message does not matter in this case.
11th Nov 2021, 8:53 PM
Lothar - avatar
+ 8
Good catch Lothar You are given code that takes the number of students who enter the university as input. Let's greet them! Task Complete the program to output "Welcome" for each student. Sample Input 2 Sample Output Welcome Welcome ChaoticDawg
11th Nov 2021, 9:13 PM
BroFar - avatar
+ 5
If I understand correctly, you want to print welcome n times, but the last time should not have a newline afterwards. You can do this by only looping n-1 times. Then after your loop, if n is greater than 0, use System.out.print("welcome") (without the ln). Or Inside the loop change println("welcome") to print("welcome") and then add an if statement to check if i < n sysout a println().
11th Nov 2021, 7:31 PM
ChaoticDawg - avatar
+ 5
Lothar Lol I'm guessing this is one of the challenges/module projects that I don't remember. Oh, well at least the OP can figure out how to not have a blank line at the end too.
11th Nov 2021, 8:57 PM
ChaoticDawg - avatar
+ 4
I can't see an empty line???
11th Nov 2021, 7:30 PM
Lisa - avatar
+ 1
11th Nov 2021, 9:33 PM
John Delvin
John Delvin - avatar
Use this code: int n = scanner.nextInt(); for (int i = 1; i <= n; i++) { System.out.print(i+" "); System.out.println("welcome"); }
13th Nov 2021, 5:03 AM
Holger Edud Angulo Castillo
Holger Edud Angulo Castillo - avatar
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(; int n = scanner.nextInt(); for (int i = 0; i < n; i++) { System.out.println("Welcome"); } } }
7th Mar 2023, 2:06 PM
Santhosh Kumar Jampala
Santhosh Kumar Jampala - avatar