① 一段最简单的java代码程序有哪些
public class HelloWorld{
public static void main(String[] args){
System.out.println("hello world!");
}
}
② 一个简单的Java程序代码
public double GetCost(int minutes)
{
//整数时间所花的费用
int aa = minutes / 60; //未满1小时处理
if (minutes < 60)
return 2;
//超出小时部分
int bb = minutes % 60; //其实你还有必要做一些其他处理。比如说超过30分钟了该怎么样算等等...... return aa * 2 + bb * 0.01d;
}
③ 求编写一个超级简单的Java的程序源代码
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
public static void main(String args[]) {
LoginFrm frame = new LoginFrm();
}
}
class LoginFrm extends JFrame implements ActionListener{
JLabel nameLabel=new JLabel("用户名:");
JLabel pwdLabel=new JLabel("密码:");
JTextField name=new JTextField(10);
JPasswordField password=new JPasswordField(10);
JButton butnSure=new JButton("确定");
JButton butnCancel=new JButton("取消");
public LoginFrm() {
super("登陆");
setBounds(500, 200, 280, 220);
setVisible(true);
setLayout(null);
nameLabel.setBounds(45, 20, 100, 25);
add(nameLabel);
add(name);
name.setBounds(105, 20, 110, 25);
add(pwdLabel);
pwdLabel.setBounds(45, 60, 100, 25);
add(password);
password.setBounds(105, 60, 110, 25);
add(butnSure);
butnSure.setBounds(45, 100, 80, 25);
add(butnCancel);
butnCancel.setBounds(135, 100, 80, 25);
butnSure.addActionListener(this);
butnCancel.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();//刷新
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() ==butnSure){
System.out.println("用户名:"+name.getText());
System.out.println("密码:"+name.getText());
if("admin".equals(name.getText().trim())&&"123".equals(password.getText().trim())){
this.dispose();
new MainFrm("用户界面",name.getText().trim(),password.getText().trim());
}else {
JOptionPane.showMessageDialog(this, "用户不存在");
}
}else if(e.getSource()==butnCancel){
System.exit(1);
}
}
class MainFrm extends JFrame{
private JLabel info;
public MainFrm(String s,String name,String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info=new JLabel("登陆成功,用户名:"+name+",密码:"+password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}
④ 求JAVA简易计算机源代码
试试这个
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class SZJSQ extends JApplet implements ActionListener
{
boolean i=true;
private JButton num0=new JButton("0");
private JButton num1=new JButton("1");
private JButton num2=new JButton("2");
private JButton num3=new JButton("3");
private JButton num4=new JButton("4");
private JButton num5=new JButton("5");
private JButton num6=new JButton("6");
private JButton num7=new JButton("7");
private JButton num8=new JButton("8");
private JButton num9=new JButton("9");
private JButton zuok=new JButton("(");
private JButton youk=new JButton(")");
private JButton dian=new JButton(".");
private JButton NULL=new JButton("N");
private JButton plu=new JButton("+");
private JButton min=new JButton("-");
private JButton mul=new JButton("x");
private JButton div=new JButton("/");
private JButton equ=new JButton("=");
private JButton cle=new JButton("C");//清除
private JTextField space=new JTextField(30);
public void init()
{
JPanel text=new JPanel();
text.setLayout(new FlowLayout());
text.add(space);
JPanel buttons=new JPanel();
buttons.setLayout(new GridLayout(5,4));
buttons.add(num9);
buttons.add(num8);
buttons.add(num7);
buttons.add(plu);
buttons.add(num6);
buttons.add(num5);
buttons.add(num4);
buttons.add(min);
buttons.add(num3);
buttons.add(num2);
buttons.add(num1);
buttons.add(mul);
buttons.add(num0);
buttons.add(cle);
buttons.add(equ);
buttons.add(div);
buttons.add(zuok);
buttons.add(youk);
buttons.add(dian);
buttons.add(NULL);
(num9).addActionListener(this);
(num8).addActionListener(this);
(num7).addActionListener(this);
(num6).addActionListener(this);
(num5).addActionListener(this);
(num4).addActionListener(this);
(num3).addActionListener(this);
(num2).addActionListener(this);
(num1).addActionListener(this);
(num0).addActionListener(this);
(plu).addActionListener(this);
(min).addActionListener(this);
(mul).addActionListener(this);
(div).addActionListener(this);
(equ).addActionListener(this);
(cle).addActionListener(this);
(zuok).addActionListener(this);
(youk).addActionListener(this);
(dian).addActionListener(this);
setLayout(new BorderLayout());
add("North",text);
add("South",buttons);
space.setText("0");
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==num9)
{
if(i==true)
{
space.setText("9");
i=false;
}
else space.setText(space.getText()+'9');
}
if(e.getSource()==num8)
{
if(i==true)
{
space.setText("8");
i=false;
}
else space.setText(space.getText()+'8');
}
if(e.getSource()==num7)
{
if(i==true)
{
space.setText("7");
i=false;
}
else space.setText(space.getText()+'7');
}
if(e.getSource()==num6)
{
if(i==true)
{
space.setText("6");
i=false;
}
else space.setText(space.getText()+'6');
}
if(e.getSource()==num5)
{
if(i==true)
{
space.setText("5");
i=false;
}
else space.setText(space.getText()+'5');
}
if(e.getSource()==num4)
{
if(i==true)
{
space.setText("4");
i=false;
}
else space.setText(space.getText()+'4');
}
if(e.getSource()==num3)
{
if(i==true)
{
space.setText("3");
i=false;
}
else space.setText(space.getText()+'3');
}
if(e.getSource()==num2)
{
if(i==true)
{
space.setText("2");
i=false;
}
else space.setText(space.getText()+'2');
}
if(e.getSource()==num1)
{
if(i==true)
{
space.setText("1");
i=false;
}
else space.setText(space.getText()+'1');
}
if(e.getSource()==num0)
{
if(i==true)
{
space.setText("0");
i=false;
}
else space.setText(space.getText()+'0');
}
if(e.getSource()==zuok)
{
if(i==true)
{
space.setText("(");
i=false;
}
else space.setText(space.getText()+'(');
} if(e.getSource()==youk)
{
if(i==false)
space.setText(space.getText()+')');
}
if(e.getSource()==dian)
{
if(i==false)
space.setText(space.getText()+'.');
}
if(e.getSource()==plu)
{
space.setText(space.getText()+'+');
i=false;
}
if(e.getSource()==min)
{
space.setText(space.getText()+'-');
i=false;
}
if(e.getSource()==mul)
{
space.setText(space.getText()+'*');
i=false;
}
if(e.getSource()==div)
{
space.setText(space.getText()+'/');
i=false;
}
if(e.getSource()==equ)
{
space.setText(String.valueOf(Calculator(space.getText())));
i=true;
}
if(e.getSource()==cle)
{
space.setText("0");
i=true;
}
}
public double Calculator(String f)//科学计算
{
int i=0,j=0,k;
char c;
StringBuffer s=new StringBuffer();
s.append(f);
s.append('=');
String formula=s.toString();
char[] anArray;
anArray=new char[50];
Stack<Character> mystack=new Stack<Character>();
while(formula.charAt(i)!='=')
{
c=formula.charAt(i);
switch(c)
{
case '(': mystack.push(new Character(c));
i++;
break;
case ')':
while(mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.pop();
i++;
break;
case '+':
case '-':
while(!mystack.empty()&&mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case '*':
case '/':
while(!mystack.empty()&&(mystack.peek().charValue()=='*'||mystack.peek().charValue()=='/'))
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case' ': i++;
break;
default: while((c>='0'&&c<='9')||c=='.')
{
anArray[j++]=c;
i++;
c=formula.charAt(i);
}
anArray[j++]='#';
break;
}
}
while(!(mystack.empty()))
anArray[j++]=mystack.pop().charValue();
i=0;
int count;
double a,b,d;
Stack<Double> mystack1 =new Stack<Double>();
while(i<j)
{
c=anArray[i];
switch(c)
{
case '+':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b+a;
mystack1.push(new Double(d));
i++;
break;
case '-':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b-a;
mystack1.push(new Double(d));
i++;
break;
case '*':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b*a;
mystack1.push(new Double(d));
i++;
break;
case '/':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
if(a!=0)
{
d=b/a;
mystack1.push(new Double(d));
i++;
}
else
{
System.out.println("Error!");
}
break;
default:
d=0;count=0;
while((c>='0'&&c<='9'))
{
d=10*d+c-'0';
i++;
c=anArray[i];
}
if(c=='.')
{
i++;
c=anArray[i];
while((c>='0'&&c<='9'))
{
count++;
d=d+(c-'0')/Math.pow(10,count);
i++;
c=anArray[i];
}
}
if(c=='#')
mystack1.push(new Double(d));
i++;
break;
}
}
return(mystack1.peek().doubleValue());
}
}
⑤ java源代码,随便简单的,要有点注释的
简单的windows计算器界面
package day11;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class CalculatorA {
private JFrame jf;
private JButton[] jbs;
private JTextField jtf;
private JButton clear;
private double num1,num2;
private char operator;
public CalculatorA(){
//实例化属性
jf=new JFrame("我的计算器v1.1");
jbs=new JButton[16];
jtf=new JTextField(25);
clear=new JButton("clear");
String str="123+456-789*0.=/";
for(int i=0;i<str.length();i++){
jbs[i]=new JButton(str.charAt(i)+"");
}
init();
setFont();
setColor();
addEventHandler();
}
public void init(){
//布局图形界面
//jf.setLayout(new BorderLayout());
JPanel jp1=new JPanel();
//jp1.setLayout(new FlowLayout());
jp1.add(jtf);
JPanel jp2=new JPanel();
jp2.setLayout(new GridLayout(4,4));
for(int i=0;i<jbs.length;i++){
jp2.add(jbs[i]);
}
JPanel jp3=new JPanel();
jp3.add(clear);
jf.add(jp1,BorderLayout.NORTH);
jf.add(jp2,BorderLayout.CENTER);
jf.add(jp3,BorderLayout.SOUTH);
}
public void setFont(){
Font f=new Font("宋体",Font.BOLD,20);
jtf.setFont(f);
for(int i=0;i<jbs.length;i++){
jbs[i].setFont(f);
}
}
public void setColor(){
}
public void addEventHandler(){
ActionListener lis=new ActionListener(){
public void actionPerformed(ActionEvent e) {
JButton jb=(JButton)e.getSource();
String str=jb.getText().trim();
//String str2=e.getActionCommand().trim();
if("0123456789.".indexOf(str)!=-1){//如果是数字或点号
jtf.setText(jtf.getText()+str);
return;
}
if("+-*/".indexOf(str)!=-1){//如果是操作符
//????
}
if(str.equals("=")){//如果是等号
//????
}
}
};
for(int i=0;i<jbs.length;i++){
jbs[i].addActionListener(lis);
}
}
public void showMe(){
jf.pack();
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new CalculatorA().showMe();
}
}
⑥ 我想看一点简单的Java程序的源代码
兄弟可以联系 hi留言也行
我这里保留了,从学习java第一天起到现在 学习练习代码,
基础部分注释很详细。
//每一位相加求和
public class Demo
{
public static void main(String[] args)
{
int i = 45678;
int sum = 0;
int c = 0;
for(int j = 4; j >= 0; j--)
{
int b = (int) Math.pow(10, j);
c = i / b;
System.out.println(c);
sum += c;
System.out.println("sum=" + sum);
i %= b;
}
System.out.println(sum);
}
}
public class ZY1030
{
public static void main(String[] asgs)
{
zy1();
zy2();
zy3();
zy4();
zy5();
zy6();
zy7();
yanghuisanjiao();
}
public static void yanghuisanjiao()
{
int[][] pas = new int[6][];
for(int i = 0; i < pas.length; i++)
{
pas[i] = new int[i + 1];
pas[i][0] = 1;
pas[i][i] = 1;
for(int j = 0; j < pas[i].length - 1; j++)
{
if(j >= 1 && i > 1)
pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
}
for(int i = 0; i < pas.length; i++)
{
for(int j = 0; j < pas[i].length; j++)
{
System.out.print(pas[i][j]);
System.out.println();
}
}
System.out.println();
}
private static void zy1()
{
System.out.println("��ҵ1");
/*
*
**
***
****
*****
******
*******
*/
for(int r = 0; r < 7; r++)
{
for(int j = 0; j < r + 1; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy2()
{
System.out.println("\n��ҵ2");
/*
*
***
*****
*******
*********
*/
for(int r = 0; r <= 5; r++)
{
for(int j = 0; j < 11 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j < r * 2 + 1; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy3()
{
System.out.println("\n��ҵ3");
/*
*
* *
* * *
* * * *
* * * * *
*/
for(int r = 0; r <= 5; r++)
{
for(int j = 0; j < 10 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j < r; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
private static void zy4()
{
System.out.println("\n��ҵ4");
/*
***********
***********
***********
***********
***********
*/
for(int r = 0; r <= 5; r++)
{
for(int j = 0; j < 7 - r; j++)
{
System.out.print(" ");
}
for(int j = 0; j < 10; j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void zy5()
{
System.out.println("\n��ҵ5");
/*
1X1=1
1X2=2 2X2=4
1X3=3 2X3=6 3X3=9
....
*/
for(int r = 1; r <= 9; r++)
{
for(int j = 1; j <= r; j++)
{
int iValue = j * r; //����ֵ
String str = j + "X" + r + "=" + iValue + " ";
System.out.print(str);
//System.out.print(" J:" + j);
}
System.out.println();
//System.out.println("R:" + r);
}
}
private static void zy6()
{
System.out.println("\n��ҵ6");
/*
������(����) ֻ�ܱ�1�ͱ����������������
3 5 7 11 13 17 19 23 ....
int n = 4;
boolean t = true; // assume is SU_SHU
for(int i=2; i<n; i++)
{
if(n%i==0)
{
t = false;
break;
}
}
System.out.println(t);
*/
for(int i = 2; i <= 100; i++)
{
// if(i % 2 ==0 || i % 3 == 0 )
// {
// continue;
// }
// System.out.print(i + " ");
boolean bTrue = true;
for(int j = 2; j < i; j++)
{
if(i % j == 0)
{
bTrue = false;
break;
}
}
if(bTrue)
{
System.out.println(i);
}
}
System.out.println();
}
private static void zy7()
{
System.out.println("\n��ҵ7");
/*
int n = 23623;
int x = n % 100000 / 10000;
System.out.println(x);
x = n % 10000 / 1000;
System.out.println(x);
x = n % 1000 / 100;
System.out.println(x);
*/
}
}
⑦ 求一个简单java程序代码,谢谢
public class TestStar {
public static void main(String[] args) {
String star = "*";
for (int i = 0; i < 5; i++) {
if (i == 0) {
System.out.print(" " + star);
System.out.println();
}
if (i == 1) {
for (int z = 0; z < 4; z++) {
System.out.print(" " + star);
}
System.out.println();
}
if (i == 2) {
System.out.print(" ");
for (int x = 0; x < 3; x++) {
System.out.print(" " + star);
}
System.out.println();
}
if (i == 3) {
for (int y = 0; y < 2; y++) {
System.out.print(" " + star + " ");
}
}
}
}
}
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)
⑧ 最简单的java程序
packagee.abc.test2;
publicclassStaff{
privateStringsNo;
privateStringsName;
privateStringsSex;
privateintsAge;
privateintsWage;
publicStaff(StringsNo,StringsName,StringsSex,intsAge,intsWage){
this.sNo=sNo;
this.sName=sName;
this.sSex=sSex;
this.sAge=sAge;
this.sWage=sWage;
}
publicStringgetSNo(){returnsNo;}
publicStringgetSName(){returnsName;}
publicStringgetSSex(){returnsSex;}
publicintgetSAge(){returnsAge;}
publicintgetSWage(){returnsWage;}
}
(4)根据类Staff的定义,创建三个该类的对象,输出每个职工的信息,计算并输出他们工资的最大值和最小值。
Staffstaff1=newStaff("1","陈老师","女",20,2000);
Staffstaff2=newStaff("2","白老师","男",24,2500);
Staffstaff3=newStaff("3","周老师","女",22,2400);
intmaxWage=Math.max(staff1.getSWage(),staff2.getSWage());
maxWage=Math.max(maxWage,staff3.getSWage());
intminWage=Math.min(staff1.getSWage(),staff2.getSWage());
minWage=Math.min(minWage,staff3.getSWage());
System.out.println(String.format("三人之中的最高工资:%d",maxWage));
System.out.println(String.format("三人之中的最低工资:%d",minWage));
⑨ 我需要一段最简单的java代码程序
public class HelloWorld{
public static void main(String[] args){
System.out.println("hello world!");
}
}
⑩ java里一个简单类的源代码
SessionFactory sessionFactory = cfg.buildSessionFactory();
你没有理解这行代码的意义,这行代码cfg.buildSessionFactory()返回的不是SessionFactory,而是实现了SessionFactory 这个接口的一个类,这个具体实现了SessionFactory接口的类是在hibernate的配置文件中配置的