Java语言基础- String类 1 length()方法与compareTo()方法的使用 - 花名册

package step1; import java.util.Scanner; public class Roster { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String roster1=scanner.nextLine(); String roster2=scanner.nextLine(); System.out.println(roster1.length()); System.out.println(roster2.length()); int u; u=roster1.compareTo(roster2); if(u==0){ System.out.println("相同"); } else{ System.out.println("不相同"); } } }

经验分享 程序员 微信小程序 职场和发展