我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

java开发小程序代码 小程序开发代码大全

用java写一个小程序

java实现先输入10个int类型的参数,之后循环判断找到最大值和最小值,保存起来和其他的值进行比较。代码如下:

关岭ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

public class Test{

public static void main(String args[]){

int i,min,max;

int A[] = new int[10];

Scanner input=new Scanner(System.in);

for(int j=0,j10;j++){//输入10个数

System.out.println("请输入一个数字:");

int length=input.nextInt();//输入一个数字

A[i] =length;

}

min=max=A[0];

System.out.print("数组A的元素包括:");

int j =0;

int n =0 ;

for(i=0;iA.length;i++)

{

System.out.print(A[i]+" ");

if(A[i]max) // 判断最大值

j =i;

max=A[i];

if(A[i]min) // 判断最小值

min=A[i];

n =i

}

System.out.println("\n数组的最大值是:"+max+".数组的位置是:"+(j+1)); // 输出最大值和最大值的位置

System.out.println("数组的最小值是:"+min+".数组的位置是:"+(n+1)); // 输出最小值

}

}

用java编一个小程序

import java.io.*;

public class BaiduJava

{

public static int[] input(String arg)

{

int n=Integer.parseInt(arg);

int i=0;

int a[]=new int[n];

while(in)

{

System.out.print("input "+(i+1)+" number :");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try

{

a[i]=Integer.parseInt(br.readLine());

}

catch(Exception e)

{

System.out.println(e.getMessage());

}

i++;

}

return a;

}

public static int[] sort(int[] a)

{

for(int i=0;ia.length-1;i++)

{

for(int j=i+1;ja.length;j++)

{

int t;

if(a[i]a[j])

{

t=a[i];

a[i]=a[j];

a[j]=t;

}

}

}

return a;

}

public static void main(String[] args)

{

int[] b=sort(input(args[0]));

for(int i=0;ib.length;i++)

System.out.print(b[i]+" ");

System.out.println();

}

}

运行过了,没问题。命令行第一个参数输入n

用java编写一个小程序

abstract class VirtualLife{

int lifeValue;

int attackPowe;

int describe;

public abstract void physicalAttack();

}

abstract class VirtualHero extends VirtualLife{

int defense;

int armor;

}

interface ISkill{

void skillFirst();

void skillSecond();

void skillThird();

void skillFourth();

}

class Ezreal extends VirtualHero implements ISkill{

String hero ="Ezreal";

public void physicalAttack() {

System.out.println(hero+"物理攻击为"+attackPowe);

}

public void skillFirst() {

System.out.println(hero+"使用了技能"+1);

}

public void skillSecond() {

System.out.println(hero+"使用了技能"+2);

}

public void skillThird() {

System.out.println(hero+"使用了技能"+3);

}

public void skillFourth() {

System.out.println(hero+"使用了技能"+4);

}

}

class Annie extends VirtualHero implements ISkill{

String hero ="Annie";

public void physicalAttack() {

System.out.println(hero+"物理攻击为"+attackPowe);

}

public void skillFirst() {

System.out.println(hero+"使用了技能"+1);

}

public void skillSecond() {

System.out.println(hero+"使用了技能"+2);

}

public void skillThird() {

System.out.println(hero+"使用了技能"+3);

}

public void skillFourth() {

System.out.println(hero+"使用了技能"+4);

}

}

class Soliders extends VirtualLife{

public void physicalAttack() {

System.out.println("我是小兵,我的攻击力为"+attackPowe);

}

}

public class Test {

public static void main(String[] args){

Ezreal ezreal=new Ezreal();

ezreal.attackPowe=10;

ezreal.physicalAttack();

Annie annie=new Annie();

annie.attackPowe=20;

annie.physicalAttack();

Soliders solider=new Soliders();

solider.attackPowe=5;

solider.physicalAttack();

}

}

用JAVA编写一个小程序,不限类型好玩点的。

控制台小游戏 class YZDEL

{

public static void main(String[] args)

{

java.util.Random Shiji = new java.util.Random();

java.util.Scanner Shuru = new java.util.Scanner(System.in);

java.util.Scanner Nandu = new java.util.Scanner(System.in);

int YingxHP = 20;

int YingxMP = 0;

int MogHP = 20;

int MogMP = 0;

int MogDo = 0;

int fangyu = 0;

System.out.println("┏━━━━╮┏━━┣┣┓ ╮ ┓┏━┳━┳┓┓━┓ ");

System.out.println("┏┣━━━┓┏━━┣┣┓ ┃┏ ┃ ┃┓┃ ╯ ");

System.out.println("┣┣━━━┫╭━━┻╯╮ ┃╰┓┃ ┃╯┏━┣━━┓");

System.out.println("┣┣━━━┫┏━━━━┓╭━━┣━┛┗━┻━┻┛┃┃");

System.out.println("┏┣━━━┓┣━━━━┫ ┃┃┃┗╮╮┃┃┣━╯");

System.out.println(" ┛┗╯┗━━━━╯┗╯╰╰━━┛┛┗━╯╰━┛");

System.out.println();

System.out.println(" 作者:天狐空幻");

System.out.println();

System.out.println("说明:勇者的操作方式为以下所示:");

System.out.println(" 使用攻击需消耗1MP 伤害1HP");

System.out.println(" 使用蓄力可增加1MP 伤害0HP");

System.out.println(" 使用躲闪需消耗0MP 伤害0HP 躲避攻击");

System.out.println(" 使用重击需消耗3MP 伤害2HP 防御无效");

System.out.println(" 恶龙攻击力高, 注意防御是取胜的关键");

System.out.println(" 恶龙MP达到4时可能会放出火焰无法躲避");

System.out.println(" 准备说明完毕,那么让我们来挑战恶龙吧!");

System.out.println("==================================");

//难度选择

System.out.println("请选择难度");

System.out.println("1.娱乐 2.挑战 3.噩梦");

int ND = Nandu.nextInt();

System.out.println("==================================");

while(true)

{

//HP,MP的显示

System.out.print("勇者: ");

System.out.print(" HP ");

for(int x=YingxHP;x0;x--) System.out.print("*");

System.out.print(" "+YingxHP);

System.out.println();

System.out.print(" ");

System.out.print(" MP ");

for(int x=YingxMP;x0;x--) System.out.print("*");

System.out.print(" "+YingxMP);

System.out.println();

System.out.print("恶龙: ");

System.out.print(" HP ");

for(int y=MogHP;y0;y--) System.out.print("*");

System.out.print(" "+MogHP);

System.out.println();

System.out.print(" ");

System.out.print(" MP ");

for(int y=MogMP;y0;y--) System.out.print("*");

System.out.print(" "+MogMP);

System.out.println();

System.out.println("==================================");

//胜利判定

if(YingxHP1) {System.out.println();System.out.println("勇者HP为0! 不..不可能..我怎么会..勇者倒下了。再接再厉吧!~");System.out.println();break;}

if(MogHP1) {System.out.println();System.out.println("恶龙HP为0! 恶龙绝望的哀鸣中倒了下去。勇者胜利了。恭喜你挑战成功!!");System.out.println();break;}

//角色输入判定

System.out.println("你要做什么:");

System.out.println("1.攻击 2.蓄力");

System.out.println("3.躲闪 4.重击");

System.out.println("____________________");

int Do = Shuru.nextInt();

//敌人输入判定

//娱乐难度

if(ND==1){

for(int i=1;i3;i++) MogDo = Shiji.nextInt(4);}

//挑战难度

if(ND==2){

if(YingxMP==0MogMP==0) {MogDo = 0;}

else if(MogMP==0){for(int i=1;i3;i++) MogDo = Shiji.nextInt(2);}

else if(YingxMP2MogMP2) MogDo = 2;

else if(MogMP4) {for(int i=1;i4;i++) MogDo = Shiji.nextInt(3);}

else MogDo = 3;}

//噩梦难度

if(ND==3){

if(Do==1) MogDo=1;

if(Do==2MogMP0) MogDo=2;

if(Do==2MogMP==0) MogDo=0;

if(Do==3MogMP4) MogDo=0;

if(Do==3MogMP=4) MogDo=3;}//变态判定。。

//战斗分析

//防御

if(Do==3) {fangyu=1;System.out.println("你灵巧的躲避攻击!");}

if(MogDo==1) {fangyu=1;System.out.println("恶龙进行防御!");}

//角色判定

if(Do==1YingxMP==0) {System.out.println("MP不足!");}

if(Do==1YingxMP0) {

if(fangyu==0) {MogHP=MogHP-1;YingxMP=YingxMP-1;System.out.println("你发动攻击!");}

if(fangyu==1) {YingxMP=YingxMP-1;System.out.println("你的攻击被格挡!");}}

if(Do==2) {YingxMP=YingxMP+1;System.out.println("你进行蓄力!");}

if(Do==4YingxMP3) {System.out.println("MP不足!");}

if(Do==4YingxMP2) {MogHP=MogHP-2;YingxMP=YingxMP-3;System.out.println("你发动重击!");}

if(Do 4) System.out.println("你不知所措...");

//敌人判定

if(MogDo==2MogMP==0) {System.out.println("恶龙在发呆!");}

if(MogDo==2MogMP0) {

if(fangyu==0) {YingxHP=YingxHP-2;MogMP=MogMP-1;System.out.println("恶龙发动攻击!");}

if(fangyu==1) {MogMP=MogMP-1;System.out.println("恶龙的攻击被躲开了!");}}

if(MogDo==0) {MogMP=MogMP+1;System.out.println("恶龙进行蓄力!");}

if(MogDo==3MogMP4) {System.out.println("恶龙在发呆!");}

if(MogDo==3MogMP3) {YingxHP=YingxHP-4;MogMP=MogMP-4;System.out.println("恶龙发动火焰吐吸!躲避不能!");}

//结束

fangyu = 0;

MogDo = 0;

System.out.println("____________________");

System.out.println();

System.out.println("=================================="); }

}

}

求java小程序代码,500行左右。。大作业用。追加50

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class mypanel extends Panel implements MouseListener

{

int chess[][] = new int[11][11];

boolean Is_Black_True;

mypanel()

{

Is_Black_True = true;

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

chess[i][j] = 0;

}

}

addMouseListener(this);

setBackground(Color.BLUE);

setBounds(0, 0, 360, 360);

setVisible(true);

}

public void mousePressed(MouseEvent e)

{

int x = e.getX();

int y = e.getY();

if(x 25 || x 330 + 25 ||y 25 || y 330+25)

{

return;

}

if(chess[x/30-1][y/30-1] != 0)

{

return;

}

if(Is_Black_True == true)

{

chess[x/30-1][y/30-1] = 1;

Is_Black_True = false;

repaint();

Justisewiner();

return;

}

if(Is_Black_True == false)

{

chess[x/30-1][y/30-1] = 2;

Is_Black_True = true;

repaint();

Justisewiner();

return;

}

}

void Drawline(Graphics g)

{

for(int i = 30;i = 330;i += 30)

{

for(int j = 30;j = 330; j+= 30)

{

g.setColor(Color.WHITE);

g.drawLine(i, j, i, 330);

}

}

for(int j = 30;j = 330;j += 30)

{

g.setColor(Color.WHITE);

g.drawLine(30, j, 330, j);

}

}

void Drawchess(Graphics g)

{

for(int i = 0;i 11;i++)

{

for(int j = 0;j 11;j++)

{

if(chess[i][j] == 1)

{

g.setColor(Color.BLACK);

g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);

}

if(chess[i][j] == 2)

{

g.setColor(Color.WHITE);

g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);

}

}

}

}

void Justisewiner()

{

int black_count = 0;

int white_count = 0;

int i = 0;

for(i = 0;i 11;i++)//横向判断

{

for(int j = 0;j 11;j++)

{

if(chess[i][j] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i][j] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 11;i++)//竖向判断

{

for(int j = 0;j 11;j++)

{

if(chess[j][i] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[j][i] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

for(i = 0;i 7;i++)//左向右斜判断

{

for(int j = 0;j 7;j++)

{

for(int k = 0;k 5;k++)

{

if(chess[i + k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i + k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

for(i = 4;i 11;i++)//右向左斜判断

{

for(int j = 6;j = 0;j--)

{

for(int k = 0;k 5;k++)

{

if(chess[i - k][j + k] == 1)

{

black_count++;

if(black_count == 5)

{

JOptionPane.showMessageDialog(this, "黑棋胜利");

Clear_Chess();

return;

}

}

else

{

black_count = 0;

}

if(chess[i - k][j + k] == 2)

{

white_count++;

if(white_count == 5)

{

JOptionPane.showMessageDialog(this, "白棋胜利");

Clear_Chess();

return;

}

}

else

{

white_count = 0;

}

}

}

}

}

void Clear_Chess()

{

for(int i=0;i11;i++)

{

for(int j=0;j11;j++)

{

chess[i][j]=0;

}

}

repaint();

}

public void paint(Graphics g)

{

Drawline(g);

Drawchess(g);

}

public void mouseExited(MouseEvent e){}

public void mouseEntered(MouseEvent e){}

public void mouseReleased(MouseEvent e){}

public void mouseClicked(MouseEvent e){}

}

class myframe extends Frame implements WindowListener

{

mypanel panel;

myframe()

{

setLayout(null);

panel = new mypanel();

add(panel);

panel.setBounds(0,23, 360, 360);

setTitle("单人版五子棋");

setBounds(200, 200, 360, 383);

setVisible(true);

addWindowListener(this);

}

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

public void windowDeactivated(WindowEvent e){}

public void windowActivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

}

public class mywindow

{

public static void main(String argc [])

{

myframe f = new myframe();

}

}


新闻名称:java开发小程序代码 小程序开发代码大全
当前路径:http://shouzuofang.com/article/dodsojj.html

其他资讯