package cntext;
import javaio;
import javautilScanner;
public class Demo {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(Systemin) ;
inputuseDelimiter("\n");
File file = new File("d:" + Fileseparator+"stutxt") ; //保存文件到d盘stutxt
PrintStream output = new PrintStream(new FileOutputStream(file));
for(int i = 0 ; i < 5 ; i ++) {
Systemoutprintln("请输入第" + (i+1) + "个学生信息,按回车键结束");
if(inputhasNext()) {
String str = inputnext();
outputprintln(str);
}
}
inputclose();
outputclose();
}
}
import javaawt;
import javaxswing;
public class MyJframe extends JFrame {
public MyJframe()
{
setLayout(new FlowLayout());
add(new JTextField(20));
add(new JButton("测试"));
setSize(400, 200);
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new MyJframe()setVisible(true);
}
}
代码如下:
public class HelloWorld {
public static void main(String []args) {
int a = 3, b = 7 ;
Systemoutprintln("Hello World!");
}
public static int f(int a, int b){
return aa + ab + bb;
}
}
结果如下:
你等我,我来写!
要加注释吗?txt文件也贴给你吧。
import javaioFile;
import javaioFileInputStream;
public class Test {
private static int excellentNum;
private static int goodNum;
private static int passNum;
private static int failNum;
private static int totalNum;
public static void count() {
String str = readFile();
String[] records = strsplit("\n");
totalNum = recordslength;
for(int i = 0; i < totalNum; i++) {
String[] record = records[i]split(" ");
String[] scoreStr = record[recordlength -1]split("\r");
int score = IntegerparseInt(scoreStr[0]);
if(score >= 90) {
excellentNum++;
}else if(score >= 70) {
goodNum++;
}
if(score >= 60) {
passNum++;
}else {
failNum++;
}
}
}
public static void countExcellent() {
Systemoutprintln("优秀率是: " + (float)excellentNum/totalNum100 + "%");
}
public static void countGood() {
Systemoutprintln("良好率是: " + (float)goodNum/totalNum100 + "%");
}
public static void countPass() {
Systemoutprintln("及格率是: " + (float)passNum/totalNum100 + "%");
}
public static void countFail() {
Systemoutprintln("不及格率是: " + (float)failNum/totalNum100 + "%");
}
public static String readFile() {
File file = new File("D:\\scoretxt");
StringBuffer sb = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[1024];
int length = 0;
while(fisavailable() > 0) {
length = fisread(b);
String str = new String(b, 0, length);
sbappend(str);
}
} catch (Exception e) {
eprintStackTrace();
}
return sbtoString();
}
public static void main(String[] args) {
count();
countExcellent();
countGood();
countPass();
countFail();
}
}
--------------------------------------
scoretxt
001 小明 90
002 小伟 38
004 好地方 80
005 小明 90
006 小伟 38
007 好地方 80
008 小明 90
009 小伟 38
010 好地方 80
001 小明 90
011 小伟 38
012 好地方 80
import javautilArrays;
import javautilCollections;
import javautilList;
import javautilScanner;
public class Total {
public static void main(String[] args) {
Scanner sc = new Scanner(Systemin);
Integer [] arrs = new Integer[10];
for (int i = 0; i < arrslength; i++) {
Systemoutprint(i + 1 + ":");
arrs[i] = scnextInt();
}
scclose();
Systemoutprintln("原始数据:" + ArraystoString(arrs));
Arrayssort(arrs);
Systemoutprintln("升序排列:" + ArraystoString(arrs));
List<Integer> list = ArraysasList(arrs);
Collectionsreverse(list);
Systemoutprintln("逆序排列:" + list);
}
}
以上就是关于求编写一个java小程序全部的内容,包括:求编写一个java小程序、用JAVA编译一个超简单的小程序,急用、求java经典小程序代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)