multiplatform

Initializing a union with a non-trivial constructor

只愿长相守 提交于 2019-11-26 12:39:15
问题 I have a structure which I create a custom constructor to initialize the members to 0\'s. I\'ve seen in older compilers that when in release mode, without doing a memset to 0, the values are not initialized. I now want to use this structure in a union, but get errors because it has a non-trivial constructor. So, question 1. Does the default compiler implemented constructor guarantee that all members of a structure will be null initialized? The non-trivial constructor just does a memset of all

How can I get the user input in Java?

青春壹個敷衍的年華 提交于 2019-11-25 22:57:00
问题 I attempted to create a calculator, but I can not get it to work because I don\'t know how to get user input . How can I get the user input in Java? 回答1: You can use any of the following options based on the requirements. Scanner class import java.util.Scanner; Scanner scan = new Scanner(System.in); String s = scan.next(); int i = scan.nextInt(); BufferedReader and InputStreamReader classes import java.io.BufferedReader; import java.io.InputStreamReader; BufferedReader br = new BufferedReader