0% found this document useful (0 votes)
24 views3 pages

Tess

java code

Uploaded by

Linn Thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Tess

java code

Uploaded by

Linn Thành
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

public class TenHelloWorlds {

public static void main(String[] args) {


for (int i = 0; i < 10; i++) {
System.out.println("Hello, World");
}
}
}
5
public class UseThree {
public static void main(String[] args) {
// Ensure the program receives exactly three arguments
if (args.length == 3) {
String firstName = args[0];
String secondName = args[1];
String thirdName = args[2];

// Print the names in reverse order


System.out.println("Hi " + thirdName + ", " + secondName + ", and " +
firstName + ".");
} else {
System.out.println("Please provide exactly three names.");
}
}
}
web ex
1.
public class HelloWorldMultilingual {
public static void main(String[] args) {
System.out.println("English: Hello, World!");
System.out.println("Spanish: ¡Hola, Mundo!");
System.out.println("French: Bonjour, le Monde!");
System.out.println("German: Hallo, Welt!");
System.out.println("Italian: Ciao, Mondo!");
System.out.println("Portuguese: Olá, Mundo!");
System.out.println("Russian: Здравствуй, мир!");
System.out.println("Chinese (Mandarin): 你好,世界!");
System.out.println("Japanese: こんにちは、世界!");
System.out.println("Korean: 안녕하세요, 세계!");
System.out.println("Hindi: नमस्ते, दुनिया!");
System.out.println("Arabic: ‫ يا عالم‬،‫;)"!مرحبًا‬
System.out.println("Greek: Γειά σου, Κόσμε!");
System.out.println("Turkish: Merhaba, Dünya!");
System.out.println("Swahili: Habari, Dunia!");
System.out.println("Hebrew: ‫ עולם‬,‫;)"!שלום‬
System.out.println("Dutch: Hallo, Wereld!");
System.out.println("Swedish: Hej, Världen!");
System.out.println("Finnish: Hei, Maailma!");
System.out.println("Polish: Witaj, Świecie!");
System.out.println("Bengali: ওহে বিশ্ব!");
System.out.println("Tamil: வணக்கம், உலகம்!");
}
}
2.public class Initials {
public static void main(String[] args) {
// Define each row of the initials "NDLT" as a single string
String[] initials = {
"* * ***** * ***********",
"** * * * * * ",
"* * * * * * * ",
"* * * * ** * ",
"* * * * ** * ",
"* * * * * * * ",
"* ** * * * * ",
"* * * * * * ",
"* * ***** * * "
};

// Print the initials


for (String row : initials) {
System.out.println(row);
}
}
}
3
Let's go through the questions based on the provided image:

3. Describe what happens if, in HelloWorld.java, you omit:

a. main: The program will not run because the main method is the entry point in a
Java application. If it's missing, the Java runtime won't know where to start.
b. String: Omitting String in the main method signature will result in a
compilation error, as the main method signature must have String[] args.
c. HelloWorld: If the class name is omitted or misspelled, the program won't
compile, as the file name should match the public class name in Java.
d. System.out: If System.out is omitted, the program will not know where to send
the output (i.e., to the console). This will cause a compilation error.
e. println: Omitting println means you're not calling the method that prints
output. If you just use System.out, it won't compile because System.out expects a
method call like println() or print().
4. Describe what happens if, in HelloWorld.java, you omit:

a. the ;: A missing semicolon will result in a compilation error because Java


expects semicolons at the end of each statement.
b. the first " (quote): This will cause a syntax error because Java requires
matching double quotes for string literals.
c. the second ": Same as above; it will cause a syntax error.
d. the first {: Omitting the opening brace will lead to a syntax error because Java
expects blocks of code to be enclosed within curly braces.
e. the second {: Similar to the first brace, omitting it will result in a syntax
error.
f. the first }: Omitting the closing brace will cause a compilation error because
the code block is not closed.
g. the second }: Same as above, it will cause a compilation error due to an
unclosed code block.
5. Describe what happens if, in HelloWorld.java, you misspell (by, say, omitting
the second letter):

a. main: Misspelling main will result in the program not finding the correct entry
point, causing a runtime error.
b. String: Misspelling String will cause a compilation error since String is a
defined class in Java.
c. HelloWorld: Misspelling the class name will result in a compilation error, as
the class name must match the file name.
d. System.out: Misspelling either System or out will result in a compilation error
because these are predefined classes and objects in Java.
e. println: Misspelling println will cause a compilation error because Java won't
recognize the method.
6. The error: java.lang.NoSuchMethodError: main
The error indicates that Java couldn't find the main method with the correct
signature. In the provided code, you have:
java
Sao chép mã
public static void main() {
System.out.println("Doesn't execute");
}
The issue is that the main method must accept a String[] args as its parameter. The
correct signature should be:
java
Sao chép mã
public static void main(String[] args) {
System.out.println("Doesn't execute");
}
With this change, the program should run correctly.

You might also like