+ 1
What is wrong with this code? I want it to output the text "Hello world" and then the "who are you". I am so new to this whole c
class MyClass { static void sayHello() { System.out.println("Hello World!") class Metall { static void hellNo() { system.out.println("who are you"); } public static void main(String[ ] args) { sayHello(); sayHello(); sayHello(); } public static void main(String)[ ] args) { hellNo(); }
4 ответов
+ 11
class MyClass {
static void sayHello() {
System.out.println("Hello World!");
}
static void hellNo() {
System.out.println("who are you");
}
public static void main(String[ ] args) {
sayHello();
sayHello();
sayHello();
hellNo();
}
}
This will print 3 times hello world.
You made some mistakes. First you cannot have 2 main(String[] args) in the same class. So you would have to move one in your first class.
You also forgot a semicolon and you wrote system instead of System with capital S.and you forgot to close braces on first method.
If you want to print hello world just once Saeed go is good !
+ 4
public class Program
{
static void sayHello() {
System.out.println("Hello World!")
;
}
static void hellNo() {
System.out.println("who are you");
}
public static void main(String[] args) {
sayHello();
hellNo();
}
}
+ 1
there are multiplemain methods here
you can call both sayHello and no hello. in same block inside
0
Yo mustn't create other main method !Never!