zoukankan      html  css  js  c++  java
  • Java初体验

    1. Write your Java source code program in a text editor and save it with a .java extension. Make sure that your text editor saves the file in plain ASCII format, and make sure that it supports long file names. You can't save a Java program as a .jav file -- the extension has to be .java.


    2. Compile your program from a command-line prompt, using the javac compiler that comes with the SDK. For example, for a source code file named Sample.java, you would type javac Sample.java. If all goes well, a Java class file will be produced. In our example, this file would be
    called Sample.class. Remember to always specify the .java extension when compiling a Java program.

    3. Run your program from a command-line prompt, using the java interpreter that comes with the SDK. For example, to run the Sample program from the previous step, you would type java Sample. To specify command-line arguments to a Java program, simply type them
    after the program name, separated by spaces. Remember to never specify the .class extension when running a Java program.

    4. Errors can occur when compiling or running a Java program. As you know, run-time errors are more difficult to debug than compile-time errors. When you are new to a language, however, compile-time error messages can seem very cryptic. Correcting compile-time errors can be very instructive, but if you can't get any of the examples in this tutorial to work。

    public class Factorial {
    public static void main(String[] args) {
    if(args.length != 0) {
    int num = Integer.parseInt(args[0]);
    System.out.println(factorial(num));
    }
    }
    private static int factorial(int fact) {
    int result = fact;
    if (fact == 0)
    return result;
    else {
    while (fact != 1)
    result *= --fact;
    }
    return result;
    }
    }
  • 相关阅读:
    C# Brush Color String 互相转换
    WPF Binding ElementName方式无效的解决方法--x:Reference绑定
    WPF动画应用-几何图形扩散动画
    Timer更新UI的合理办法
    员工管理
    EF CodeFirst 实例Demo
    C# 星期相关代码实例
    WPF Canvas实现进度条
    DispatcherTimer 应用实例
    数据库操作命令
  • 原文地址:https://www.cnblogs.com/allenblogs/p/2233268.html
Copyright © 2011-2022 走看看