Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static int calculateLengthWithByte(String str) {
        int length = 0;
        for (int i = 0; i < str.length(); i++) {
            char tmp = str.charAt(i);
            if (tmp > 0 && tmp < 127) {
                length += 1;
            } else {
                length += 2;
            }
        }
        return length;
    }
}