Radiation properties of terahertz (THz) electromagnetic waves emitted from stacks of 3 and 50 intrinsic Josephson junctions by flowing bias currents have been numerically investigated for high-frequency device applications. A novel multibranch structure in the resistive state was obtained for the current-voltage characteristics of the stacks. Each branch corresponded to an individual mode of a two-dimensional cavity resonance for Josephson plasma waves in the directions parallel and perpendicular to the c-axis of the stack. The electromagnetic field distribution in the stack exhibited standing-wave patterns not only for the in-phase mode between junctions but also for the other modes in different branches. Maximum radiation power was attained for the in-phase mode, and the corresponding bias point was measured for the 3- and 50-junction stacks. The peak power in the 50-junction stack was approximately 50 times larger than that in the 3-junction stack. The frequency spectra at maximum power exhibited a sharp main peak and a few harmonics. These properties are useful in designing a THz oscillator using intrinsic Josephson junctions.