0

Friendly Robot help with the method

public static void welcome() {; There's no output and it's expected to have "Welcome!" Help Please?

5th Dec 2021, 9:20 AM
peter
12 Respostas
+ 2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int numberOfPeople = read.nextInt(); for (int i = 0; i < numberOfPeople; i++) { welcome(); } } public static void welcome() { //complete the method } }
5th Dec 2021, 11:23 AM
peter
+ 1
really confused, i though it was easy but nothing is easy in programming....
5th Dec 2021, 9:29 AM
peter
+ 1
peter Your code is so off track that no-one knows how to respond. Java Tutorial 2.1 offers this possibility. class MyClass { public static void main(String[ ] args) { System.out.println("Welcome"); } } But you mentioned using a method? Can you be more specific with what you are attempting.
5th Dec 2021, 10:52 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
The following might help you, but you must understand how methods work. A method is created as a self contained bit of code which only produces a result when called. Think of it as a little machine that only makes something when it is turned on. So first you must make the machine. Then when you are running your code in main(), you must call its function to get the output. for (int i = 0; i < numberOfPeople; i++) { welcome(); //calls method } } // this section creates the method public static void welcome() { System.out.println("Welcome"); }
5th Dec 2021, 9:56 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
this is an empty method: public static void welcome() { //complete the method } //complete the method means: here is the place where you have to write the rest (body) of method
6th Dec 2021, 12:27 AM
zemiak
+ 1
Thank you all for helping me, really appericate it đŸ€™
6th Dec 2021, 3:24 AM
peter
+ 1
I have tried to print the text but it's showing error.
6th Dec 2021, 1:40 PM
Jay Prakash
Jay Prakash - avatar
+ 1
Done it in another way
6th Dec 2021, 2:10 PM
Jay Prakash
Jay Prakash - avatar
0
but I'm confused where to put and complete the method
5th Dec 2021, 12:31 PM
peter
0
The last method where it says //complete the method // this section creates the method public static void welcome() { System.out.println("Welcome"); }
6th Dec 2021, 1:54 PM
peter
0
Yes i have tried but now it's showing no symbol found.
6th Dec 2021, 1:56 PM
Jay Prakash
Jay Prakash - avatar
0
public static void welcome() { System.out.println(“Welcome!”); }
6th Dec 2021, 1:57 PM
peter