主要是字符串位置的问题,以下程序可以满足你的要求。String s = "10.2.3";System.out.println(s.substring(0,s.indexOf('.', s.indexOf('.')+1)));