Ultima modifica:
Hi, there are some errors. First the indentation of the code: the main must be indented with respect to the outer class. Then you used the "length2" variable without declaring or initializing it. Finally, you have erroneously associated "length1" with "str2", but this is not a real error: for code clarity, associate "length1" with "str1". You should do something like this:
Don't use the syntax abbreviation if you are a beginner and if you have any other doubts let us know. Bye
Java:
import java.util.*;
public class Main {
public static void main(String[] args) {
// Variable declaration and initialization
String str1 = "pizza";
String str2 = "mandolino";
String result = "";
int length1 = str1.length();
int length2 = str2.length();
// Check conditions on strings
if (length1 > 0){
result += str1.charAt(0);
} else {
result += '#';
}
if (length2 > 0){
result += str2.charAt(length2 - 1);
} else {
result += '#';
}
// Printout of the result
System.out.println(result);
}
}
Don't use the syntax abbreviation if you are a beginner and if you have any other doubts let us know. Bye