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

  • 相关阅读:
    The user specified as a definer (”@’%') does not exist解决方法
    mongodb下载地址
    镜像系统,超好用
    部署mysql后,无法设置用户远程登陆(%只所有用户,不可以,只能给指定的ip?)
    Libcap的简介及安装
    GCC命令基础
    gcc安装(centos)
    React Native 踩坑
    webpack 和 babel
    React 开发笔记
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/3579906.html
Copyright © 2011-2022 走看看