成都网站建设设计

将想法与焦点和您一起共享

java50行简单代码的简单介绍

求一个50行左右的JAVA代码,最好每行带注释,谢谢啦

/*这个相当详细了.

创新互联建站服务项目包括德兴网站建设、德兴网站制作、德兴网页制作以及德兴网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,德兴网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到德兴省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

程序也不算太难.而且给老师看的时候效果比较好.因为有图形化界面,又实现一个比较实用的功能.老师会比较高兴的.

建立一个文件名为Change.java就可以编译了*/

/*

* 这个程序实现输入身高算出标准体重,输入体重,算出身高的功能

*/

import java.awt.*; //导入相关类包,这才样使用相应awt图形界面的类

import java.awt.event.*;//同上

public class Change extends Frame { //定义一个类Change, 父类是Frame(图形界面的)

Button b = new Button("互查"); //创建一个按钮的对象b,显示为"互查"

Label l1 = new Label("身高(cm)");//创建一个lable.显示身高

Label l2 = new Label("体重(kg)");//创建一个lable 显示体重

double heigth, weigth; //定义变量

double x, y; //定义变量

TextField tf1 = new TextField(null, 10);//添加Text框

TextField tf2 = new TextField(null, 10);//添加Text框

public Change() {//类的构造函数,完成初始化

super("互查表");//创建窗口,标题为互查表

setLayout(new FlowLayout(FlowLayout.LEFT));//设置布局

add(l1);//把lable 身高放到window里

add(tf1);//把Text 框 放到窗口上

add(l2); //把lable 体重放到window里

add(tf2);//Test放到窗口里

add(b);//把button放到窗口上

pack();//自动放到窗口里排列上边的组件

setVisible(true);//可以让用户看到窗口

addWindowListener(new WindowAdapter() {//如果按 X, 关闭窗口

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

b.addActionListener(new ButtonListener());//添加button监听函数

}

class ButtonListener implements ActionListener {//实现click button时功能操作

public void actionPerformed(ActionEvent e) {//当click调用

if (tf1.getText()!=null) {//检查tf1 test 是否为空

try {//取异常

x = Double.parseDouble(tf1.getText());//字符转为double型

weigth = (x - 100) * 0.9;//算重量

tf2.setText("" + weigth);//显示重量

} catch (NumberFormatException ex) {

tf1.setText("");//如果输入不是数字,设为空

}

}

if (tf1.getText().equals("")==true){//tf1是否为空

y = Double.parseDouble(tf2.getText());//把tf2里的文本转为double 型 的

heigth = y / 0.9 + 100; //算身高根据重量

tf1.setText("" + heigth);}//显示身高

}

}

public static void main(String[] args) {//主函数,程序入口

new Change(); //建立类Change的对象,并调用他的构造函数Change().显示窗口

}

}

50行左右的java程序代码,要求代码内含有两个循环,两个函数,50行,急需

随便给你写了一个

package com.wys.util;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

public class Test {

public static ListInteger smallNumbers,largeNumbers;

public static int sum1 = 0,sum2 = 0;

public static void main(String[] args) {

smallNumbers = new ArrayListInteger();

largeNumbers = new ArrayListInteger();

run();

}

public static void run() {

int i = 0;

for (int j = 0; j 50; j++) {

Random rand = new Random();

i = rand.nextInt(1000);

if (i500) {

small(i);

}else{

large(i);

}

}

System.out.println("随机输出的50个数字中:");

System.out.println("大于500的数(包括500)共有"+largeNumbers.size()+"个");

System.out.print("他们是"+largeNumbers);

System.out.println();

System.out.println("他们的和是"+sum1);

System.out.println("小于500的数共有"+smallNumbers.size()+"个");

System.out.print("他们是"+smallNumbers);

System.out.println();

System.out.println("他们的和是"+sum2);

}

private static void large(int number) {

largeNumbers.add(number);

sum1 += number;

}

private static void small(int number) {

smallNumbers.add(number);

sum2 += number;

}

}

一段java代码,可运行出来,至少50行代码,最好可以注释一下

就把打字游戏的给你吧

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.util.Random;

class WordPanel extends JPanel implements Runnable{

private Thread thread = null;

private int level = 1;

private Font font = new Font("宋体",Font.ITALIC+Font.BOLD,24);

private Color color = Color.BLUE;

public static final int x = 10;

private int y = 0;

private char word;//下落的字母

private static Random rand = new Random();

public void setY(int y){

this.y = y;

}

public void setWord(char word){

this.word = word;

}

public char getWord(){

return this.word;

}

public static char newChar(){

return (char)(97+rand.nextInt(26));

}

public WordPanel(){

word = newChar();

thread = new Thread(this);

thread.start();

}

public void paintComponent(Graphics g) {

super.paintComponent(g);

g.setFont(font);

g.setColor(color);

g.drawString(String.valueOf(word),x,y);

}

public void run(){

while (true){

try {

Thread.sleep(1000);

this.repaint();

if (y=this.getHeight()){

y = 0;

word = this.newChar();

}else

y+=20;

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}

}

public class WordGame extends JFrame{

private WordPanel[] words = new WordPanel[10];

class Listener extends KeyAdapter{

public void keyTyped(KeyEvent e) {

char input = e.getKeyChar();

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

if ( input==words[i].getWord() ){

words[i].setWord(WordPanel.newChar());

words[i].setY(0);

words[i].repaint();

break;

}

}

}

}

public WordGame(String title){

super(title);//思考

Container c = this.getContentPane();

c.setLayout(new GridLayout(1,words.length));

this.addKeyListener( new Listener() );

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

words[i] = new WordPanel();

c.add(words[i]);

}

this.setSize( new Dimension(400,400) );

this.setVisible(true);

}

public static void main(String[] args){

WordGame game = new WordGame("简单的打字游戏");

}

}

谁能给一个Java程序代码我,要50行到100行就可以啦。最好有几行解释

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.Properties;

/**

* java应用对配置文件的读写

*

* @author

* @version

*

*/

public class PropertyMgr {

private static Properties props = new Properties();

private static FileInputStream in = null;

private static FileOutputStream out = null;

static {

try {

// 从当前类路径下的配置文件

props.load(PropertyMgr.class.getClassLoader().getResourceAsStream("System.properties"));

// 从指定文件名读入配置信息

in = new FileInputStream("System.properties");

props.load(in);

in.close();

} catch (IOException e) {

e.printStackTrace();

}

}

/**

* 获取键所对应的值

*

* @param key

* 要得到值的键

* @return

*/

public static String getProperty(String key) {

return props.getProperty(key);

}

/**

* 改变或添加一个key的值 当key存在于properties文件中时该key的值被value所代替, 当key不存在时,该key的值是value

*

* @param key

* 要存入的键

* @param value

* 要存入的值

*/

public static String setProperty(String key, String value) {

try {

props.setProperty(key, value);

} catch (RuntimeException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

String urlFile = new File("System.properties").getAbsolutePath();

String tempUrl = urlFile.substring(urlFile.indexOf(File.separator));

out = new FileOutputStream(tempUrl);

props.store(out, null);

out.close();

} catch (FileNotFoundException e) {

System.out.println("系统找不到指定的路径");

e.printStackTrace();

} catch (IOException ioe) {

ioe.printStackTrace();

}

return "页面名称保存成功";

}

/**

* 将更改后的文件数据存入指定的文件中,该文件可以不存在,但是路径文件所在的文件夹一定得存在。

*

* @param fileName

* 文件路径+文件名称

* @param description

* 对该文件的描述

*/

public static String saveFile() {

try {

String urlFile = new File("System.properties").getAbsolutePath();

String tempUrl = urlFile.substring(urlFile.indexOf(File.separator));

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

out = new FileOutputStream(tempUrl);

props.store(out, null);

out.close();

} catch (FileNotFoundException e) {

System.out.println("系统找不到指定的路径");

e.printStackTrace();

} catch (IOException ioe) {

ioe.printStackTrace();

}

return "保存成功";

}

}


网站题目:java50行简单代码的简单介绍
文章源于:http://chengdu.cdxwcx.cn/article/hhgees.html