簡單的java代碼大全 最簡單的java代碼

求一個簡單又有趣的JAVA小游戲代碼

具體如下:

臨湘ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為創新互聯的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

連連看的小源碼

package Lianliankan;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戲按鈕數組

JButton exitButton,resetButton,newlyButton; //退出,重列,重新開始按鈕

JLabel fractionLable=new JLabel("0"); //分數標簽

JButton firstButton,secondButton; //

分別記錄兩次62616964757a686964616fe59b9ee7ad9431333335326239被選中的按鈕

int grid[][] = new int[8][7];//儲存游戲按鈕位置

static boolean pressInformation=false; //判斷是否有按鈕被選中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標

int i,j,k,n;//消除方法控制

代碼(code)是程序員用開發工具所支持的語言寫出來的源文件,是一組由字符、符號或信號碼元以離散形式表示信息的明確的規則體系。

對于字符和Unicode數據的位模式的定義,此模式代表特定字母、數字或符號(例如 0x20 代表一個空格,而 0x74 代表字符“t”)。一些數據類型每個字符使用一個字節;每個字節可以具有 256 個不同的位模式中的一個模式。

在計算機中,字符由不同的位模式(ON 或 OFF)表示。每個字節有 8 位,這 8 位可以有 256 種不同的 ON 和 OFF 組合模式。對于使用 1 個字節存儲每個字符的程序,通過給每個位模式指派字符可表示最多 256 個不同的字符。2 個字節有 16 位,這 16 位可以有 65,536 種唯一的 ON 和 OFF 組合模式。使用 2 個字節表示每個字符的程序可表示最多 65,536 個字符。

單字節代碼頁是字符定義,這些字符映射到每個字節可能有的 256 種位模式中的每一種。代碼頁定義大小寫字符、數字、符號以及 !、@、#、% 等特殊字符的位模式。每種歐洲語言(如德語和西班牙語)都有各自的單字節代碼頁。

雖然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代碼頁中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代碼頁中卻不同。如果在運行不同代碼頁的計算機間交換數據,必須將所有字符數據由發送計算機的代碼頁轉換為接收計算機的代碼頁。如果源數據中的擴展字符在接收計算機的代碼頁中未定義,那么數據將丟失。

如果某個數據庫為來自許多不同國家的客戶端提供服務,則很難為該數據庫選擇這樣一種代碼頁,使其包括所有客戶端計算機所需的全部擴展字符。而且,在代碼頁間不停地轉換需要花費大量的處理時間。

求一Java代碼,要簡單的。大概一百多行的的。

題目:一球從100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地時,共經過多少米?第10次反彈多高?

這個題目,下面我會貼出來兩種代碼。其實這個題目,我煩了簡單計算,想搞得有趣味性一點,結果耽誤了好幾天時間,最后發現搞的也不好。

先第一種,為了解題而解題。

==== Main.java ====

public class Main {

private double TotalHeight = 100;

private double CurHeight = 50;

public void drop(int times) {

if ((times - 1) == 0) {

return;

}

setTotalHeight(getTotalHeight() + 2 * getCurHeight());

setCurHeight(getCurHeight() / 2);

drop(times - 1);

}

public double getTotalHeight() {

return TotalHeight;

}

public void setTotalHeight(double totalHeight) {

TotalHeight = totalHeight;

}

public double getCurHeight() {

return CurHeight;

}

public void setCurHeight(double curHeight) {

CurHeight = curHeight;

}

public static void main(String[] args) {

Main main = new Main();

main.drop(2);

System.out.println("Total height is " +

main.getTotalHeight());

System.out.println("Current height is " +

main.getCurHeight());

}

}

==== 然后是第二種 =====

==== Main.java ====

package main;

import javax.swing.JFrame;

import panel.BallPanel;

import time.Delay;

public class MainFrame extends JFrame {

public MainFrame(String title) {

super(title);

}

public static void main(String[] args) {

Delay delay = new Delay();

MainFrame frame = new MainFrame("Hello JFrame");

BallPanel ballPanel = new BallPanel();

frame.add(ballPanel);

frame.setSize(500, 500);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

delay.initDelay();

ballPanel.setDelay(delay.getDelay());

ballPanel.loopDrop(0);

}

}

==== Delay.java ====

package time;

public class Delay {

public void initDelay() {

int g = 10;

int i = 0;

double s, t, t0 = 0.0;

delay = new int[100];

for (s = 100; s 10100; s += 100) {

t = Math.sqrt(2 * s / g);

delay[i++] = (int) ((t - t0) * 100);

t0 = t;

}

}

public int[] getDelay() {

return delay;

}

private int delay[];

}

==== BallPanel.java ====

package panel;

import java.awt.Color;

import java.awt.Graphics;

import javax.swing.JPanel;

public class BallPanel extends JPanel {

public BallPanel() {

super();

}

public void paint(Graphics g) {

g.clearRect(0, 0, this.getWidth(), this.getHeight());

g.setColor(Color.BLUE);

g.fillOval(250, ballCenter, 30, 30);

}

public void loopDrop(int height) {

int i;

if (this.height == height) { // At bottom

for (i = 0; i targetHeight; i += MUL) {

ballCenter = this.height - i;

this.repaint();

try {

Thread.sleep(delay[(targetHeight - i - 1) / MUL]);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

loopDrop(this.height - i);

} else { // At top

for (i = height; i this.height; i += MUL) {

ballCenter = i;

this.repaint();

try {

Thread.sleep(delay[(i - height) / MUL]);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

targetHeightV = targetHeightV / 2;

targetHeight = targetHeightV;

if (targetHeight != 0) {

loopDrop(i);

}

}

}

public void setDelay(int delay[]) {

this.delay = delay;

}

private int extracted() {

return 100 * MUL;

}

private int targetHeight = extracted();

private int targetHeightV = extracted();

private int ballCenter = 0;

private int height = extracted();

private int delay[];

private final int MUL = 4;

}

其實所謂的第二種,是用的JFrame在JPanel上畫圖,直觀的展示出來每次彈起來的效果。因為100像素實在太小了,所以我做了一個變量MUL,相

當于是等比例擴大的效果。問題就是彈不到10次距離就用光了,所以。。。。。權當娛樂了。。當然可以等比例在放大,例如100M看成是10000像素,這

樣能多彈幾次。這個程序,最后球就在那里不動了,程序不會自己退出。

求一個簡單的JAVA游戲代碼,100行左右,謝謝!

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Painter extends JFrame{

/**

*

*/

private static final long serialVersionUID = 8160427604782702376L;

CanvasPanel canvas = new CanvasPanel();;

public Painter() {

super("Star");

this.add(canvas);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.pack();

this.setResizable(false);

this.setLocationRelativeTo(null);

this.setVisible(true);

}

public static void main(String[] args) {

new Painter();

}

}

class CanvasPanel extends JPanel implements ActionListener{

/**

*

*/

private static final long serialVersionUID = -4642528854538741028L;

private JButton[] btn = new JButton[4];

private String[] btn_name = {"+", "-", "R", "L"};

private int center_x = 200, center_y = 200, radius = 100, degree = 0;

public CanvasPanel() {

this.setPreferredSize(new Dimension(400, 500));

this.setLayout(null);

for(int i = 0; i 4; i++) {

btn[i] = new JButton(btn_name[i]);

btn[i].setBounds(160 + i * 60, 425, 50, 50);

btn[i].addActionListener(this);

this.add(btn[i]);

}

}

@Override

public void paintComponent(Graphics g) {

super.paintComponent(g);

for(int i = 0; i 5; i++) {

g.drawLine( (int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i))),

(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i))),

(int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i + 144))),

(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i + 144))));

}

}

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getActionCommand() == "+") {

if(radius 200)

radius += 2;

repaint();

} else if(e.getActionCommand() == "-") {

if(radius 0)

radius -= 2;

repaint();

} else if(e.getActionCommand() == "R") {

degree = (degree + 2) % 360;

repaint();

} else if(e.getActionCommand() == "L") {

degree = (degree - 2) % 360;

repaint();

}

}

}

一個簡單的Java程序代碼?

package com.zpp;public class Charge {

public static void main(String [] args) {

if(args.length ==0) {

System.out.println("parameter error!");

System.out.println("java com.zpp.Charge [int]");

return;

}

int min = Integer.parseInt(args[0]);

double money = 0.0;

if (min = 0) {

money =0.0;

System.out.println("not money");

} else if (min = 60) {

money = 2.0;

} else {

money = 2.0 + (min - 60) * 0.01;

}

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

}

} 編譯:javac -d . Charge.java運行:java com.zpp.Charge 111

求一段簡單的java代碼

不知道是否理解對了你的意思,大概寫了一下:

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.StringReader;

import java.io.StringWriter;

public class FileReadAndWrite {

private static final int DEFAULT_BUFFER_SIZE = 1024;

public static void main(String[] args) {

File file = new File("E:/workspace/FileIOTest/src/a.txt");

String str = file2String(file, "UTF-8");

str = str.replace('d', 'f');

string2File(str,"E:/workspace/FileIOTest/src/b.txt");

System.out.println("處理完畢");

}

/**

* 文本文件轉換為指定編碼的字符串

*

* @param file

* 文本文件

* @param encoding

* 編碼類型

* @return 轉換后的字符串

* @throws IOException

*/

public static String file2String(File file, String encoding) {

InputStreamReader reader = null;

StringWriter writer = new StringWriter();

try {

if (encoding == null || "".equals(encoding.trim())) {

reader = new InputStreamReader(new FileInputStream(file),

encoding);

} else {

reader = new InputStreamReader(new FileInputStream(file));

}

// 將輸入流寫入輸出流

char[] buffer = new char[DEFAULT_BUFFER_SIZE];

int n = 0;

while (-1 != (n = reader.read(buffer))) {

writer.write(buffer, 0, n);

}

} catch (Exception e) {

e.printStackTrace();

return null;

} finally {

if (reader != null)

try {

reader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

// 返回轉換結果

if (writer != null)

return writer.toString();

else

return null;

}

/**

* 將字符串寫入指定文件(當指定的父路徑中文件夾不存在時,會最大限度去創建,以保證保存成功!)

*

* @param res

* 原字符串

* @param filePath

* 文件路徑

* @return 成功標記

*/

public static boolean string2File(String res, String filePath) {

boolean flag = true;

BufferedReader bufferedReader = null;

BufferedWriter bufferedWriter = null;

try {

File distFile = new File(filePath);

if (!distFile.getParentFile().exists())

distFile.getParentFile().mkdirs();

bufferedReader = new BufferedReader(new StringReader(res));

bufferedWriter = new BufferedWriter(new FileWriter(distFile));

char buf[] = new char[1024]; // 字符緩沖區

int len;

while ((len = bufferedReader.read(buf)) != -1) {

bufferedWriter.write(buf, 0, len);

}

bufferedWriter.flush();

bufferedReader.close();

bufferedWriter.close();

} catch (IOException e) {

e.printStackTrace();

flag = false;

return flag;

} finally {

if (bufferedReader != null) {

try {

bufferedReader.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

return flag;

}

}

給段最簡單的java代碼 讓我新手看一下

最簡單的java代碼肯定就是這個了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是應該是所有學java的新手看的第一個代碼了。如果是零基礎的新手朋友們可以來我們的java實驗班試聽,有免費的試聽課程幫助學習java必備基礎知識,有助教老師為零基礎的人提供個人學習方案,學習完成后有考評團進行專業測試,幫助測評學員是否適合繼續學習java,15天內免費幫助來報名體驗實驗班的新手快速入門java,更好的學習java!

文章題目:簡單的java代碼大全 最簡單的java代碼
URL地址:http://m.kartarina.com/article34/dodsese.html

成都網站建設公司_創新互聯,為您提供標簽優化品牌網站設計虛擬主機網站設計公司品牌網站建設網站營銷

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

外貿網站建設
主站蜘蛛池模板: 亚洲中文字幕久久精品无码APP| 亚洲AV日韩AV高潮无码专区| 97性无码区免费| 免费无码不卡视频在线观看| 丰满日韩放荡少妇无码视频| 亚洲综合无码无在线观看| 国产成人无码aa精品一区| 午夜不卡无码中文字幕影院| 国产成人无码精品久久久小说| 久久久人妻精品无码一区| 无码人妻精品一区二区蜜桃| 久久精品aⅴ无码中文字字幕| 亚洲av无码偷拍在线观看| 久久久久亚洲AV成人无码网站| 亚洲一本大道无码av天堂| 亚洲av无码无线在线观看 | 免费无码成人AV片在线在线播放| 久久久久亚洲精品无码网址| 午夜寂寞视频无码专区| 67194成l人在线观看线路无码| 久久久国产精品无码免费专区| 国产精品无码DVD在线观看| 天堂一区人妻无码| 亚洲中文字幕无码av永久| 亚洲国产成人无码av在线播放| 无码人妻精品一区二区三区在线| 成人无码网WWW在线观看| 国产成人AV无码精品| 无码毛片一区二区三区视频免费播放 | 色综合久久无码五十路人妻| 国产羞羞的视频在线观看 国产一级无码视频在线| 日韩乱码人妻无码系列中文字幕| 久久无码无码久久综合综合| 国产午夜片无码区在线播放 | 亚洲精品一级无码鲁丝片 | 最新亚洲人成无码网www电影| 毛片一区二区三区无码| 免费无码A片一区二三区| 成人免费一区二区无码视频| 嫩草影院无码av| 中文AV人妻AV无码中文视频 |