zoukankan      html  css  js  c++  java
  • java的一些程序

    1、文件读取并打印

    import java.io.*;
    public class readandprint{
    //*********Found********
    public static void main(String args[]) throws Exception{
    long filePoint = 0 ;
    String s;
    RandomAccessFile file = new RandomAccessFile("D:\javaceshu\readandprint.java","r");
    long fileLength = file.length();
    while (filePoint<fileLength){
    //*********Found********
    s = file.readLine();
    System.out.println(s); 
    filePoint = file.getFilePointer();
                                }
    file.close();
        }
    }

    2、图形程序显示乘法

    import javax.swing.JOptionPane;
    public class Java_1 {
    public static void main( String args[] ) {
    int x, y, result;
    String xVal, yVal;
    xVal = JOptionPane.showInputDialog( "输入第1个整数:" );
    yVal = JOptionPane.showInputDialog( "输入第2个整数:" );
    //*********Found********
    x = Integer.parseInt(xVal);
    y = Integer.parseInt( yVal );
    result = x * y;
    //*********Found********
    JOptionPane.showMessageDialog( null, "两个数的积: " + result );
    System.exit( 0 );
    }
    }

    3、从命令行参数输入 java_24_3 7 (先编译完后)会显示7的阶乘是5040

    public class _24_3{
    public static void main(String[] args){
    String num;
    if(args.length > 0)
    //*********Found********
    num =args[0];
    else
    num = "5";
    //*********Found********
    int input = Integer.parseInt(num);
    int result = Java_3(input);
    System.out.println(input+ " 的阶乘是 "+ result);
    }
    public static int Java_3(int x)
    {
    if( x < 0 )
    return 0;
    int fact = 1;
    while(x > 1)
    {
    //*********Found********
    fact = fact * x;
    x = x-1;
    }
    return fact;
    }

  • 相关阅读:
    quagga源码学习--BGP协议的初始化
    Golang pprof heap profile is empty
    python requests 配置超时及重试次数
    SVN: bdb: BDB1538 Program version 5.3 doesn't match environment version 4.7
    OpenSSL Command-Line HOWTO
    树莓派保卫战--防止SSH暴力破解
    Mac OS X Tips
    Git Tips
    SQL分组多列统计(GROUP BY后按条件分列统计)
    Show Linux Package Sort By Size
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/3579906.html
Copyright © 2011-2022 走看看