Java编程:代码注释、数学运算、变量使用与用户输入处理
1. 代码注释的使用
在Java编程中,注释是一种非常有用的工具,它可以帮助我们解释代码的功能和用途,也能提醒我们在开发过程中使用特定代码版本的原因。
我们可以通过创建一个名为 CommentingCode.java
的Java类文件来实验基本的注释方法。以下是示例代码:
package com.sg.foundations.basics.core;
public class CommentingCode {
public static void main(String[] args) {
// Comments are written to explain code in an easily
// understandable way
// Basically for single lines
// anything after // is considered a comment
System.out.println("Normal code is compiled and runs ...");
System.out.println("Comments however ... ");// do not execute!
// Comments can be on their own line
System.out.println("..."); // or they can share l