java - Cut off last half of String -
i need cut off half of user-entered string. i've tried , didn't work:
scanner sc = new scanner(system.in); string nameone = sc.nextline(); chars[] onechars = new char[nameone.length]; double onelength = onechars.length / 2; math.round(onelength); int onelen = (int)onelength; string nameonefinal = ""; for(int = 0; == onelen--; i++) { onechars[i] = onechars[onelen]; nameonefinal = nameonefinal + onechars[i]; }
final int mid = nameone.length() / 2; string[] parts = { nameone.substring(0, mid), // 1st part nameone.substring(mid), // 2nd part };
Comments
Post a Comment