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;
    }

  • 相关阅读:
    两数相除(leetcode29)
    基本数据类型与包装数据类型的使用标准
    BigDecimal
    整型包装类值的比较
    实现strStr()(leetcode28)
    移除数组(leetcode27)
    删除排序数组中的重复项(leetcode26)
    mybatis.xml配置文件详解
    多表连接
    动态SQL
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/3579906.html
Copyright © 2011-2022 走看看