import?java.applet.Applet;
成都創(chuàng)新互聯專注于企業(yè)網絡營銷推廣、網站重做改版、常山網站定制設計、自適應品牌網站建設、HTML5、商城網站建設、集團公司官網建設、成都外貿網站制作、高端網站制作、響應式網頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為常山等各大城市提供網站開發(fā)制作服務。
import?java.awt.Button;
import?java.awt.Color;
import?java.awt.Graphics;
import?java.awt.TextField;
import?java.awt.event.ActionEvent;
public?class?Nicki?extends?Applet{
private?static?final?long?serialVersionUID?=?1L;
private?Button?ok;
private?int?num=32;
private?int?resu=0;
private?boolean?isRig=false;
private?TextField?iPut;
public?Nicki(){
this.setLayout(null);
ok=new?Button("OK");
ok.setActionCommand(getName());
ok.setBounds(150,?150,?40,?20);
iPut=new?TextField();
this.add(iPut);
iPut.setBounds(100,?150,?40,?20);
this.add(ok);
ok.addActionListener(new?ButtonAction(this));
}
public?void?paint(Graphics?g){
g.setColor(Color.white);
g.fillRect(0,?0,?this.getWidth(),?this.getHeight());
g.setColor(Color.BLACK);
g.drawString("Please?guess?a?number?",?10,?20);
g.drawString("between?1?and?100",?10,?40);
if(isRig==falseresu!=0){
if(resunum){
g.drawString(""+resu+"?is?too?big?!",?10,?100);
}else?if(resunum){
g.drawString(resu+"is?too?small?!",?10,?100);
}
}else?if(isRig==true){
g.setColor(Color.GREEN);
g.drawString("Yes,"+resu+"?is?the?right?number",?10,?80);
g.drawString("Your?are?great!?",?10,?100);
g.setColor(Color.red);
g.drawString(resu+"!",?70,?120);
}
iPut.setText("");
g.drawString("Input?the?number:",?0,?150);
}
public?void?ButtonActionPerformed(ActionEvent?e){
if(e.getActionCommand().equals("panel0")){
resu=Integer.parseInt(iPut.getText());
if(num==resu){
isRig=true;
}else{
isRig=false;
}
repaint();
}
}
}
class?ButtonAction?implements?java.awt.event.ActionListener{
Nicki?su;
public?ButtonAction(Nicki?bun){
this.su=bun;
}
public?void?actionPerformed(ActionEvent?e)?{
su.ButtonActionPerformed(e);
}
}
import?java.util.Scanner;
public?class?next?{
public?static?void?main(String[]?args)?{
System.out.print("請依次輸入貸款總額,月利率,年數");
Scanner?sc?=?new?Scanner(System.in);
double?dkze?=?sc.nextDouble();
double?ylv?=?sc.nextDouble();
double?ns?=?sc.nextDouble();
next?nx?=?new?next();
nx.jisuan(dkze,ylv,ns);
}
public?void?jisuan(double?dkze,double?ylv,double?ns)?{
double?yzfje?=?0;
yzfje?=?(dkze*ylv/100)/(1-1/Math.pow(1+ylv,ns*12));
System.out.println("月支付金額為:"+yzfje);
}
}
這是我曉得的最簡單的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);
//創(chuàng)建驅動
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() {
}
}