网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java小程序代码短 小程序代码大小

急求大神发几个java 300行代码的小程序 简单点的

/**

成都创新互联公司专注于滦南企业网站建设,响应式网站开发,商城网站建设。滦南网站建设公司,为滦南等地区提供建站服务。全流程按需定制网站,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

* 文件名:Operation.java 2014-1-2 下午3:06:37

* @author Administrator

*/

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.Scanner;

import cc.icoc.javaxu.datas.StudentInfo;

/**

* @author 许仕永

* 创建时间: 2014 2014-1-2 下午3:06:37

*/

public class Operation

{

int stuNo,stuAge;

String stuName,stuClass,stuSex;

ArrayListStudentInfo list;

/**程序入口

* @param args

*/

public static void main(String[] args)

{

// TODO Auto-generated method stub

new Operation().operation();

}

private int inputInt()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

private String inputStr()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

private void operation()

{

// TODO Auto-generated method stub

if(list == null)

{

list = new ArrayListStudentInfo();

}

while(true)

{

System.out.println("\t\t\t学生信息管理系统\n");

System.out.println("1.信息查阅");

System.out.println("2.信息查询");

System.out.println("3.信息录入");

System.out.println("4.退出系统");

int what = inputInt();

if ( what == 1 )

{

getInfo();

} else if ( what == 2 )

{

allSerach();

} else if ( what == 3 )

{

inputInfo();

} else if( what == 4 )

{

System.out.println("已经退出系统");

System.exit(0);

}

}

}

/**

* 获取全部学生的信息列表

*/

private void getInfo()

{

if(!list.isEmpty())

{

for ( int i = 0; i list.size(); i++ )

{

System.out.println(list.get(i));

}

}

}

/**

* 执行查找

*/

private void allSerach()

{

System.out.println("1.输入学号进行查询");

System.out.println("2.输入姓名进行查询");

int what = inputInt();

if(what == 1)

{

System.out.println("请输入学号:");

search(inputInt());

}

else

{

System.out.println("请输入姓名:");

search(inputStr());

}

}

/**

* 按学生姓名查询学生信息

* @param name 学生姓名

*/

private StudentInfo search(String name)

{

for ( int i = 0; i list.size(); i++ )

{

if(list.get(i).getStuName().equals(name))

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查询到该名字的学生");

return null;

}

/**

* 按学号查询学生信息

* @param id 学号

*/

private StudentInfo search(int id)

{

for ( int i = 0; i list.size(); i++ )

{

if(list.get(i).getStuNo()==id)

{

System.out.println(list.get(i));

return list.get(i);

}

}

System.out.println("未查询到该学号的学生");

return null;

}

/**

* 录入学生信息

*/

private void inputInfo()

{

try

{

System.out.print("请输入学生学号:\n");

stuNo = inputInt();

System.out.print("请输入学生姓名:\n");

stuName = inputStr();

System.out.print("请输入学生性别:\n");

stuSex = inputStr();

System.out.print("请输入学生年龄:\n");

stuAge = inputInt();

System.out.print("请输入学生班级:\n");

stuClass = inputStr();

list.add(new StudentInfo(stuNo, stuAge, stuName, stuSex, stuClass));

} catch (Exception e)

{

// TODO: handle exception

System.out.println("不允许为空,请重新输入");

}

}

}

package cc.icoc.javaxu.action;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Stu

{

int countStu = 0;

int sum = 0;

int avg = 0;

ListStuBean list = new ArrayListStu.StuBean();

public static void main(String[] args)

{

new Stu().go();

}

private void go()

{

A:while(true)

{

//构造实体Bean来存储学生成绩

StuBean bean = new StuBean();

System.out.println("请输入成绩:");

System.out.println("语文:");

bean.setYuwen(scanner());

System.out.println("数学:");

bean.setMath(scanner());

//获取英语成绩

System.out.println("英语:");

bean.setEnglish(scanner());

//存入容器

list.add(bean);

for ( int i = 0; i list.size(); i++ )

{

sum += list.get(i).english+list.get(i).math+list.get(i).yuwen;

}

avg = sum / (3*list.size());

System.out.println("当前有"+list.size()+"条学生记录,所有学生总分="+sum+"平均分为"+avg);

//输入y继续录入学生信息,输入x退出

System.out.println("\n已成功录入一个学生的数据,是否继续/退出(y/x)");

if("x".equals(scannerString()))

break A;

}

}

/**输入*/

private int scanner()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextInt();

}

/**输入*/

private String scannerString()

{

Scanner scanner = new Scanner(System.in);

return scanner.nextLine();

}

class StuBean

{

int math;

int yuwen;

int english;

public int getMath()

{

return math;

}

public void setMath(int math)

{

this.math = math;

}

public int getYuwen()

{

return yuwen;

}

public void setYuwen(int yuwen)

{

this.yuwen = yuwen;

}

public int getEnglish()

{

return english;

}

public void setEnglish(int english)

{

this.english = english;

}

}

}

/**

* 文件名:StudentInfo.java 2014-1-2 下午3:07:29

* @author Administrator

*/

package cc.icoc.javaxu.datas;

/**

* @author 许仕永

* 创建时间: 2014 2014-1-2 下午3:07:29

*/

public class StudentInfo

{

int stuNo,stuAge;

String stuName,stuSex,stuClass;

public StudentInfo(int stuNo, int stuAge, String stuName, String stuSex, String stuClass)

{

super();

this.stuNo = stuNo;

this.stuAge = stuAge;

this.stuName = stuName;

this.stuSex = stuSex;

this.stuClass = stuClass;

}

public int getStuNo()

{

return stuNo;

}

public void setStuNo(int stuNo)

{

this.stuNo = stuNo;

}

public int getStuAge()

{

return stuAge;

}

public void setStuAge(int stuAge)

{

this.stuAge = stuAge;

}

public String getStuName()

{

return stuName;

}

public void setStuName(String stuName)

{

this.stuName = stuName;

}

public String getStuSex()

{

return stuSex;

}

public void setStuSex(String stuSex)

{

this.stuSex = stuSex;

}

public String getStuClass()

{

return stuClass;

}

public void setStuClass(String stuClass)

{

this.stuClass = stuClass;

}

@Override

public String toString()

{

// TODO Auto-generated method stub

String s = "学号:"+getStuNo()+"\t姓名:"+getStuName()+" \t性别:"+getStuSex()+"\t年龄:"+getStuAge()+"\t班级:"+getStuClass();

return s;

}

}

谁能给个JAVA的小程序代码,越小越好!

这是我晓得的最简单的java小程序代码了你可以看看:

package com.kenki.emp;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import java.sql.SQLException;

import java.sql.*;

public class emp extends HttpServlet {

private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables

public void init() throws ServletException {

}

//Process the HTTP Get request

public void doGet(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

response.setContentType(CONTENT_TYPE);

PrintWriter out = response.getWriter();

String code = request.getParameter("code");

String name = request.getParameter("name");

String pay = request.getParameter("pay");

System.out.println("empcode:" + code);

System.out.println("name:" + name);

System.out.println("pay:" + pay);

//创建驱动

new com.microsoft.jdbc.sqlserver.SQLServerDriver();

String strd =

"jdbc:microsoft:sqlserver://localhost:1433;databasename=emp_dates";

String username = "sa";

String pws = "";

try {

java.sql.Connection conn = java.sql.DriverManager.getConnection(

strd, username, pws);

String strs = "insert into emp values(?,?,?)";

java.sql.PreparedStatement pre = conn.prepareStatement(strs);

pre.setString(1, code);

pre.setString(2, name);

pre.setString(3, pay);

pre.execute();

pre.close();

conn.close();

//重定向至查询页面

out.println("成功保存!!");

response.sendRedirect("emp.html");

} catch (SQLException ss) {

ss.printStackTrace();

response.sendRedirect("/WebModule1/error.html");

}

}

//Process the HTTP Post request

public void doPost(HttpServletRequest request, HttpServletResponse response) throws

ServletException, IOException {

doGet(request, response);

}

//Clean up resources

public void destroy() {

}

}

JAVA小程序编写

1.JavaPow.java

import java.util.Scanner;

public class JavaPow {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("请输入一个数求平方:");

double num = sc.nextDouble();

System.out.println(num + "的平方结果是:" + Math.pow(num, 2));

}

}

2.CompareTest.java

public class CompareTest {

public static void main(String[] args) {

int a = 10, b = 8;

if(ab){

System.out.println("排序结果是:"+b+"\t"+a);

}else{

System.out.println("排序结果是:"+a+"\t"+b);

}

}

}

3.RateMoney.java

import java.util.Scanner;

public class RateMoney {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double money=0;

double rate=0;

System.out.print("请输入汇款金额:");

money=sc.nextDouble();

if(money0){

rate=0;

}

else if(money0money=100){

rate=1;

}else if(money100money=5000){

rate=money/100;

}else{

rate=50;

}

System.out.println("汇"+money+"元钱需汇款费:"+rate+"元");

}

}

三个都已经写出来了..

你好好看看吧!!

祝你早日成功!

急求JAVA小程序代码(20分重赏)

try{

final int EOF = -1;

HashTable h = new HashTable();

Reader r = new FileReader(new File(args[0]));

int c = r.read();

while (c != EOF){

System.out.print((char)c); // 未作缓冲

Character key = new Character((char)c);

Object count = h.get(key);

if (count == null){count = new Integer(1);}

else {count = new Integer(((Integer)count).intValue + 1);}

h.put(key, count);

c = r.read();

}

}catch{...}

求JAVA大神给我发一段完整可运行的java图形小程序的代码(不用太多类),谢谢了

/*计算器*/

import java.awt.*;

import javax.swing.*;

import javax.swing.border.*;

import java.awt.event.*;

public class Calculator implements ActionListener{

JFrame frame;

JPanel panel;

JTextField tfShow;/*定义显示文本框*/

JButton b1[]=new JButton[10]; /*数字按钮*/

JButton b2[]=new JButton[6]; /*操作按钮*/

boolean isNumber;/*判断是否输入多位数字的变量*/

double number;/*存储输入数值、显示结果的变量*/

double result;/*存储中间运算结果的变量*/

char operator;/*存储当前操作符的成员变量*/

public Calculator(){

frame=new JFrame("计算器");

frame.setSize(300,300);/*指定框架窗口的大小*/

frame.setResizable(false);/*使框架窗口不可改变大小*/

JPanel contentPane=(JPanel)frame.getContentPane();

contentPane.setBorder(new EmptyBorder(20,20,20,20));/*绘制框架的指定大小的空透明边框*/

tfShow=new JTextField("0",25);/*指定属性的文本域*/

tfShow.setHorizontalAlignment(JTextField.RIGHT);/*设置文本域中文本的对齐方式*/

isNumber=true;/*初始值设置*/

number=0;/*初始值设置*/

result=0;/*初始值设置*/

operator=' ';/*初始值设置*/

for(int i=0;ib1.length;i++){

b1[i]=new JButton(Integer.toString(i));/*创建数字按钮*/

b1[i].setActionCommand(Integer.toString(i));

b1[i].addActionListener(this);

b1[i].setForeground(Color.blue);

}

String bs[]={"/","*","-","C","+","="};

for(int i=0;ib2.length;i++){

b2[i]=new JButton(bs[i]);/*创建操作按钮*/

b2[i].setActionCommand(bs[i]);

b2[i].addActionListener(this);

b2[i].setForeground(Color.red);

}

panel=new JPanel();

panel.setLayout(new GridLayout(4,5));

panel.add(b1[1]);

panel.add(b1[2]);

panel.add(b1[3]);

panel.add(b2[0]);

panel.add(b1[4]);

panel.add(b1[5]);

panel.add(b1[6]);

panel.add(b2[1]);

panel.add(b1[7]);

panel.add(b1[8]);

panel.add(b1[9]);

panel.add(b2[2]);

panel.add(b1[0]);

panel.add(b2[3]);

panel.add(b2[4]);

panel.add(b2[5]);

frame.add(tfShow,BorderLayout.NORTH);/*将文本框放置在框架上方*/

frame.add(panel,BorderLayout.CENTER);/*将装有按钮组的panel放在框架的中心*/

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*设置框架窗口的默认窗口关闭操作*/

frame.setVisible(true);/*设置框架可见*/

}

public double getDisplay(){/*返回要显示的结果*/

return number;

}

public void reDisplay(){/*刷新文本域的内容*/

tfShow.setText(""+getDisplay());

}

/*对输入数字的处理*/

public void numberProcess(int num){

if(isNumbernum!=0){

String s1=Integer.toString(num);

String s2=Integer.toString((int)(this.number));

this.number=Double.parseDouble(s2+s1);/*对多位数字的处理*/

}else{

this.number=num;

}

isNumber=true;/*输入连续数字(即多位数字)时为真*/

public void operationProcess(char operator){/*根据输入的操作符改变当前操作符*/

switch(operator){

case '-':

this.operator='-';

break;

case '+':

this.operator='+';

break;

case '*':

this.operator='*';

break;

case '/':

this.operator='/';

break;

}

result=number;

isNumber=false;/*输入操作符时表示输入连续数字的标记变量为假*/

public void clear(){

number=0;

result=0;

}  

public void equal(){/*计算运算结果*/

switch(operator){

case '-':

result=result-number;

break;

case '+':

result=result+number;

break;

case '*':

result=result*number;

break;

case '/':

result=result/number;

break;

case ' ':

result=number;

break;

}

number=result; /*把运算结果赋值给显示变量*/

isNumber=false;

operator=' '; 

public static void main(String args[]){

Calculator cal=new Calculator();/*创建计算器*/

}

public void actionPerformed(ActionEvent e){

String command=e.getActionCommand();/*获取按钮激发的操作事件的命令名称*/

char c=command.charAt(0);/*将按钮命令名称的第一个字符赋值给一个字符c*/

switch(c){

case '1':

case '2':

case '3':

case '4':

case '5':

case '6':

case '7':

case '8':

case '9':

case '0':

int number=Integer.parseInt(command);

numberProcess(number);/*输入数字的处理*/

break;

case '+':

case '-':

case '*':

case '/':

operationProcess(c);/*算数运算符的处理*/

break;

case '=':equal();break;/*计算运算结果*/

case 'C':clear();break;/*清零*/

}

reDisplay(); /*在文本域中显示信息*/

}

}

运行截图:


当前标题:java小程序代码短 小程序代码大小
本文URL:http://bjjierui.cn/article/hhdcds.html

其他资讯