博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java的一些程序
阅读量:7072 次
发布时间:2019-06-28

本文共 1424 字,大约阅读时间需要 4 分钟。

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

转载于:https://www.cnblogs.com/bluewelkin/p/3579906.html

你可能感兴趣的文章
常用算法之二分查询python&php
查看>>
Securing Web Applications with Apache Shiro(2)
查看>>
boost学习之--shared_ptr
查看>>
python 学习网站
查看>>
Centos7 install python-rrdtoll-1.47 erro
查看>>
npm ERR! code EINTEGRITY 解决方法
查看>>
深受程序员鄙视的外行语录!
查看>>
使用runtime Associate方法关联的对象,需要在主对象dealloc的时候释放么?
查看>>
不健康的IT狗,送给你们一句话
查看>>
进程列表中多个JAVA进程的区分识别
查看>>
IPHONE实景导航开发总结
查看>>
Git常用操作命令
查看>>
正则表达式-断言
查看>>
用git合并分支时,如何保持某些文件不被合并
查看>>
局部代码块、构造代码块、静态代码块
查看>>
聚类分析 ---- K-Means算法
查看>>
C語言最新標準-C11 「轉」
查看>>
SaltStack数据系统-Grains详解
查看>>
课程第三天内容《基础交换 三 》
查看>>
Spring(八):缓存
查看>>