用str1.equal(str2)去比较字符串是否相等。
java做法:
import java.util.Scanner; public class text01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String[] str_sz = str.split(" "); for(int i = str_sz.length-1;i>=0;i--){ if(str_sz[i].equals(" ")){ continue; } System.out.printf(str_sz[i]+" "); } } }
纯纯小白,如有不对敬请指正。