Hello, I tried some exercises: Entering a first and a lastname, the return should be the last name in uppercase.
Example:
input: John Doe
output: John DOE
unfortunately i get a "null null", where is my mistake??
import java.util.Scanner; public class A3 { static String inData; static String firstname; static String lastname; public static void main(String[] args){ Scanner scan = new Scanner(System.in); inData=scan.next(); for(int index=0; index<inData.length(); index++){ if(inData.charAt(index) == ' ') { firstname=inData.substring(0, index-1); lastname=inData.substring(index+1, inData.length()); lastname=lastname.toUpperCase(); } else { } } System.out.println(firstname + " " + lastname); } }