朝文分享(2) C与Java之间的异同(一)

2023-11-27 23:15:11 字數 3557 閱讀 6669

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是learningyard新学苑。

今天为大家带来。

c与j**a之间的异同(一)”

欢迎您的访问。

share interest, spread happiness, increase knowledge, and le**e beautiful.

dear, this is the learingyard academy! today, the editor brings the similarities and differences between c and j**a (1),welcome to visit!一、定义变量的异同。

在c中, 变量的定义较简单, 但是字符串需要用 “char”型数组来定义。

in c, the definition of variables is **r, but strings need to be defined with an array of type "char".

在j**a中, 基本类型变量的定义与c 是差不多的。 j**a不仅包含了c中的而且有了扩充, 如范围为 -128~127的 “byte”类型, 表示真假的 “boolean”类型,不用数组定义的 “string”类型。 此外, 在j**a中 “float”和“long”的定义需要在后面加个代表类型的字母 --f” 和“l” (大小写均可).

in j**a, the definition of basic type variables is much the same as in c. j**a not only contains c and has an extension, such as the range of -128~127 "byte" type, indicating the true and false "boolean" type, do not define the array "string" type. in addition, the definitions of "float" and "long" in j**a need to be followed by a letter representing the type - f" and "l" (either case).

二、输入输出的异同。

在c中输入数据时, 先定义, 后用scanf()语句输入。 输出用固定的printf()语句, 也可以调用函数,如putchar().

when you enter data in c, you define it first and then enter it with the scanf() statement. the output is a fixed printf() statement, or you can call a function such as putchar().

在j**a中输入数据时, 首先需要引用j**a.util.scanner, 然后定义一个scanner型变量, 最后用定义的scanner型变量调用nextint()方法, 一共三步, 完成输入。 是某型就用某型的方法, 如 “float”型用nextfloat(),string”型用next().此外, 第一步在该文件中只用写一次, 第二步在该类中只用写一次, 第三步则输入一个数据就写一次。

when you input data in j**a, you first need to reference j**a.util.scanner, then define a scanner variable, and finally use the defined scanner variable to call nextint() method, a total of three steps to complete the input. if it is a certain type, use a certain type of method, such as "float" type with nextfloat(),string" type with next().in addition, the first step is written only once in the file, the second step is written only once in the class, and the third step is written once in the input data.

在j**a中输出比较多样, 可以直接调用system.out中输出方法进行输出, 可以用加号连接。 根据图中输出可知, 换行符和c一样, 为 ‘’但是像第二个一样写的话, 会进行一个ascii码的运算, 导致输出错误。 若数据前面出现字符串, 则换行符输出正常。 所以为避免错误, 直接用println()方法, 相当与将 ‘’写了在方法中。

in j**a, the output is more diverse, you can directly call the output method in system.out for output, you can use the plus sign connection. according to the output in the figure, it can be seen that the newline is' 'like c. but if you write it like the second one, an ascii operation will be performed, resulting in an output error. if the string appears before the data, the newline output is normal. so to **oid errors, use the println() method directly, which is equivalent to writing in the method.

今天的分享就到这里了,如果您对文章有独特的想法,欢迎给我们留言。让我们相约明天,祝您今天过得开心快乐!that's all for today's sharing. if you h**e a unique idea about the article, please le**e us a message, and let us meet tomorrow. i wish you a nice day!参考资料。

翻译:网易有道翻译。

本文由learningyard学苑整理并发出,如有侵权请后台留言沟通。

文案|dongyang

排版|dongyang

审核|yue

learning yard 新学苑。

生死之间 解读“享年”与“终年”在中国文化中的微妙差异

在中国文化中,享年 与 终年 这两个词语看似只差一个字,却承载着完全不同的含义。这微妙的差异不仅反映了中国古代严格的社会等级结构和谨慎的礼仪规范,也展现了对生死的不同态度。从古代的丧葬仪式到现代的讣告用语,这两个词语的使用方式都在反映着中国人对生命 年龄和逝者的独特思考。自古以来,中国就形成了系统而...

异性之间的暧昧和喜欢,这样分辨

金秋 动态创作节 你有没有感觉,我们之间有点暧昧?这是我曾经在一次朋友聚会上听到的一句话。那个说这句话的人是我的一个好朋友,我们从大学时代开始就共同走过了许多年。听到他这样问,我心里不禁升起了一股莫名的兴奋和好奇。不可否认,在异性之间,暧昧和喜欢这两种情感确实存在着细微而微妙的区别。为了更好地理解这...

文化差异下的故事 当唐朝皇帝与日本公主的文化碰撞

引言。曾经,有一段时光,唐朝与日本之间发生了一段难忘的故事。这段历史不仅让我们回顾了文化的交融和差异,更诠释了在异国他乡生活所需的适应和理解。让我们探索这个令人着迷的历史片段,看看其中的文化碰撞是如何影响了这段令人难忘的时代。文化交融与差异。入乡随俗,这句古训道出了在陌生文化中生存的智慧。每个地方都...