+ 1
Help
how can i print the results without printing out the last empty line https://code.sololearn.com/c7KjY63zEym1/?ref=app
9 odpowiedzi
+ 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.
+ 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
+ 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().
+ 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.
+ 4
I can't see an empty line???
+ 1
Ok
0
Use this code:
int n = scanner.nextInt();
for (int i = 1; i <= n; i++)
{
System.out.print(i+" ");
System.out.println("welcome");
}
0
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++)
{
System.out.println("Welcome");
}
}
}