欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

java源代碼100例的簡(jiǎn)單介紹

java新手,求完整的源代碼

//都是從新手過(guò)來(lái)的,以下代碼供參考

站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到濮陽(yáng)縣網(wǎng)站設(shè)計(jì)與濮陽(yáng)縣網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:網(wǎng)站制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋濮陽(yáng)縣地區(qū)。

//1.

public?class?BankAccount?{

private?static?String?acctnum;

private?static?double?money;

private?static?void?showAcct()?{

System.out.println("賬號(hào)為:?"?+?acctnum);

}

private?static?void?showMoney()?{

System.out.println("余額為:?"?+?money);

}

public?BankAccount(String?acc,?double?m)?{

this.acctnum?=?acc;

this.money?=?m;

}

public?static?void?main(String[]?args)?{

BankAccount?ba?=?new?BankAccount("626600018888",?5000.00);

ba.showAcct();

ba.showMoney();

}

}

//2.

public?class?Triangle?{

private?static?float?a;

private?static?float?b;

private?static?float?c;

public?Triangle(float?a,?float?b,?float?c)?{

this.a?=?a;

this.b?=?b;

this.c?=?c;

}

public?static?boolean?judgeTriangle(float?a,?float?b,?float?c)?{

if?((a??Math.abs(b?-?c)??a??b?+?c)

?(b??Math.abs(a?-?c)??b??a?+?c)

?(c??Math.abs(a?-?b)??c??a?+?b))

return?true;

else

return?false;

}

public?float?getCircumference()?{

return?this.a?+?this.b?+?this.c;

}

}

//3.

public?class?TestTriangle?{

public?static?void?main(String[]?args)?{

Triangle?t?=?new?Triangle(5.3f,7.8f,9.3f);

if(t.judgeTriangle(5.3f,7.8f,9.3f)){

System.out.print("能夠成三角形,周長(zhǎng)為:?");

System.out.printf("%9.2f",t.getCircumference());}

else

System.out.println("不能構(gòu)成三角形");

}

}

求個(gè)簡(jiǎn)單點(diǎn)的Java程序 100行左右。 需要解釋。

貪吃蛇游戲 望采納

import java.awt.Button;

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.Point;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

import java.util.*;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

public class Snake extends JFrame implements KeyListener{

int Count=0;

Button[][] grid = new Button[20][20];

ArrayListPoint snake_list=new ArrayListPoint();

Point bean=new Point(-1,-1);//保存隨機(jī)豆子【坐標(biāo)】

int Direction = 1; //方向標(biāo)志 1:上 2:下 3:左 4:右

//構(gòu)造方法

public Snake()

{

//窗體初始化

this.setBounds(400,300,390,395);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GridLayout f=new GridLayout(20,20);

this.getContentPane().setBackground(Color.gray);

this.setLayout(f);

//初始化20*20個(gè)按鈕

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

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

{

grid[i][j]=new Button();

this.add(grid[i][j]);

grid[i][j].setVisible(false);

grid[i][j].addKeyListener(this);

grid[i][j].setBackground(Color.blue);

}

//蛇體初始化

grid[10][10].setVisible(true);

grid[11][10].setVisible(true);

grid[12][10].setVisible(true);

grid[13][10].setVisible(true);

grid[14][10].setVisible(true);

//在動(dòng)態(tài)數(shù)組中保存蛇體按鈕坐標(biāo)【行列】信息

snake_list.add(new Point(10,10));

snake_list.add(new Point(11,10));

snake_list.add(new Point(12,10));

snake_list.add(new Point(13,10));

snake_list.add(new Point(14,10));

this.rand_bean();

this.setTitle("總分:0");

this.setVisible(true);

}

//該方法隨機(jī)一個(gè)豆子,且不在蛇體上,并使豆子可見(jiàn)

public void rand_bean(){

Random rd=new Random();

do{

bean.x=rd.nextInt(20);//行

bean.y=rd.nextInt(20);//列

}while(snake_list.contains(bean));

grid[bean.x][bean.y].setVisible(true);

grid[bean.x][bean.y].setBackground(Color.red);

}

//判斷擬增蛇頭是否與自身有碰撞

public boolean is_cross(Point p){

boolean Flag=false;

for(int i=0;isnake_list.size();i++){

if(p.equals(snake_list.get(i) )){

Flag=true;break;

}

}

return Flag;

}

//判斷蛇即將前進(jìn)位置是否有豆子,有返回true,無(wú)返回false

public boolean isHaveBean(){

boolean Flag=false;

int x=snake_list.get(0).x;

int y=snake_list.get(0).y;

Point p=null;

if(Direction==1)p=new Point(x-1,y);

if(Direction==2)p=new Point(x+1,y);

if(Direction==3)p=new Point(x,y-1);

if(Direction==4)p=new Point(x,y+1);

if(bean.equals(p))Flag=true;

return Flag;

}

//前進(jìn)一格

public void snake_move(){

if(isHaveBean()==true){//////////////有豆子吃

Point p=new Point(bean.x,bean.y);//【很重要,保證吃掉的是豆子的復(fù)制對(duì)象】

snake_list.add(0,p); //吃豆子

grid[p.x][p.y].setBackground(Color.blue);

this.Count++;

this.setTitle("總分:"+Count);

this.rand_bean(); //再產(chǎn)生一個(gè)豆子

}else{///////////////////無(wú)豆子吃

//取原蛇頭坐標(biāo)

int x=snake_list.get(0).x;

int y=snake_list.get(0).y;

//根據(jù)蛇頭坐標(biāo)推算出擬新增蛇頭坐標(biāo)

Point p=null;

if(Direction==1)p=new Point(x-1,y);//計(jì)算出向上的新坐標(biāo)

if(Direction==2)p=new Point(x+1,y);//計(jì)算出向下的新坐標(biāo)

if(Direction==3)p=new Point(x,y-1);//計(jì)算出向左的新坐標(biāo)

if(Direction==4)p=new Point(x,y+1);//計(jì)算出向右的新坐標(biāo)

//若擬新增蛇頭碰壁,或纏繞則游戲結(jié)束

if(p.x0||p.x19|| p.y0||p.y19||is_cross(p)==true){

JOptionPane.showMessageDialog(null, "游戲結(jié)束!");

System.exit(0);

}

//向蛇體增加新的蛇頭坐標(biāo),并使新蛇頭可見(jiàn)

snake_list.add(0,p);

grid[p.x][p.y].setVisible(true);

//刪除原蛇尾坐標(biāo),使蛇尾不可見(jiàn)

int x1=snake_list.get(snake_list.size()-1).x;

int y1=snake_list.get(snake_list.size()-1).y;

grid[x1][y1].setVisible(false);

snake_list.remove(snake_list.size()-1);

}

}

@Override

public void keyPressed(KeyEvent e) {

if(e.getKeyCode()==KeyEvent.VK_UP Direction!=2) Direction=1;

if(e.getKeyCode()==KeyEvent.VK_DOWN Direction!=1) Direction=2;

if(e.getKeyCode()==KeyEvent.VK_LEFT Direction!=4) Direction=3;

if(e.getKeyCode()==KeyEvent.VK_RIGHT Direction!=3) Direction=4;

}

@Override

public void keyReleased(KeyEvent e) { }

@Override

public void keyTyped(KeyEvent e) { }

public static void main(String[] args) throws InterruptedException {

Snake win=new Snake();

while(true){

win.snake_move();

Thread.sleep(300);

}

}

}

速求用JAVA語(yǔ)言寫(xiě)聊天室的源代碼

【ClientSocketDemo.java 客戶(hù)端Java源代碼】

import java.net.*;

import java.io.*;

public class ClientSocketDemo

{

//聲明客戶(hù)端Socket對(duì)象socket

Socket socket = null;

//聲明客戶(hù)器端數(shù)據(jù)輸入輸出流

DataInputStream in;

DataOutputStream out;

//聲明字符串?dāng)?shù)組對(duì)象response,用于存儲(chǔ)從服務(wù)器接收到的信息

String response[];

//執(zhí)行過(guò)程中,沒(méi)有參數(shù)時(shí)的構(gòu)造方法,本地服務(wù)器在本地,取默認(rèn)端口10745

public ClientSocketDemo()

{

try

{

//創(chuàng)建客戶(hù)端socket,服務(wù)器地址取本地,端口號(hào)為10745

socket = new Socket("localhost",10745);

//創(chuàng)建客戶(hù)端數(shù)據(jù)輸入輸出流,用于對(duì)服務(wù)器端發(fā)送或接收數(shù)據(jù)

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

//獲取客戶(hù)端地址及端口號(hào)

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

//向服務(wù)器發(fā)送數(shù)據(jù)

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

//從服務(wù)器接收數(shù)據(jù)

response = new String[3];

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

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

//執(zhí)行過(guò)程中,有一個(gè)參數(shù)時(shí)的構(gòu)造方法,參數(shù)指定服務(wù)器地址,取默認(rèn)端口10745

public ClientSocketDemo(String hostname)

{

try

{

//創(chuàng)建客戶(hù)端socket,hostname參數(shù)指定服務(wù)器地址,端口號(hào)為10745

socket = new Socket(hostname,10745);

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

response = new String[3];

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

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

//執(zhí)行過(guò)程中,有兩個(gè)個(gè)參數(shù)時(shí)的構(gòu)造方法,第一個(gè)參數(shù)hostname指定服務(wù)器地址

//第一個(gè)參數(shù)serverPort指定服務(wù)器端口號(hào)

public ClientSocketDemo(String hostname,String serverPort)

{

try

{

socket = new Socket(hostname,Integer.parseInt(serverPort));

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());

String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");

out.writeUTF(ip);

out.writeUTF(port);

response = new String[3];

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

{

response[i] = in.readUTF();

System.out.println(response[i]);

}

}

catch(UnknownHostException e){e.printStackTrace();}

catch(IOException e){e.printStackTrace();}

}

public static void main(String[] args)

{

String comd[] = args;

if(comd.length == 0)

{

System.out.println("Use localhost(127.0.0.1) and default port");

ClientSocketDemo demo = new ClientSocketDemo();

}

else if(comd.length == 1)

{

System.out.println("Use default port");

ClientSocketDemo demo = new ClientSocketDemo(args[0]);

}

else if(comd.length == 2)

{

System.out.println("Hostname and port are named by user");

ClientSocketDemo demo = new ClientSocketDemo(args[0],args[1]);

}

else System.out.println("ERROR");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

【ServerSocketDemo.java 服務(wù)器端Java源代碼】

import java.net.*;

import java.io.*;

public class ServerSocketDemo

{

//聲明ServerSocket類(lèi)對(duì)象

ServerSocket serverSocket;

//聲明并初始化服務(wù)器端監(jiān)聽(tīng)端口號(hào)常量

public static final int PORT = 10745;

//聲明服務(wù)器端數(shù)據(jù)輸入輸出流

DataInputStream in;

DataOutputStream out;

//聲明InetAddress類(lèi)對(duì)象ip,用于獲取服務(wù)器地址及端口號(hào)等信息

InetAddress ip = null;

//聲明字符串?dāng)?shù)組對(duì)象request,用于存儲(chǔ)從客戶(hù)端發(fā)送來(lái)的信息

String request[];

public ServerSocketDemo()

{

request = new String[3]; //初始化字符串?dāng)?shù)組

try

{

//獲取本地服務(wù)器地址信息

ip = InetAddress.getLocalHost();

//以PORT為服務(wù)端口號(hào),創(chuàng)建serverSocket對(duì)象以監(jiān)聽(tīng)該端口上的連接

serverSocket = new ServerSocket(PORT);

//創(chuàng)建Socket類(lèi)的對(duì)象socket,用于保存連接到服務(wù)器的客戶(hù)端socket對(duì)象

Socket socket = serverSocket.accept();

System.out.println("This is server:"+String.valueOf(ip)+PORT);

//創(chuàng)建服務(wù)器端數(shù)據(jù)輸入輸出流,用于對(duì)客戶(hù)端接收或發(fā)送數(shù)據(jù)

in = new DataInputStream(socket.getInputStream());

out = new DataOutputStream(socket.getOutputStream());

//接收客戶(hù)端發(fā)送來(lái)的數(shù)據(jù)信息,并顯示

request[0] = in.readUTF();

request[1] = in.readUTF();

request[2] = in.readUTF();

System.out.println("Received messages form client is:");

System.out.println(request[0]);

System.out.println(request[1]);

System.out.println(request[2]);

//向客戶(hù)端發(fā)送數(shù)據(jù)

out.writeUTF("Hello client!");

out.writeUTF("Your ip is:"+request[1]);

out.writeUTF("Your port is:"+request[2]);

}

catch(IOException e){e.printStackTrace();}

}

public static void main(String[] args)

{

ServerSocketDemo demo = new ServerSocketDemo();

}

}

求java隨即產(chǎn)生20個(gè)1到100間數(shù)的源代碼?

public class Test5{

public static void main(String []args){

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

int []arr=new int[20];

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

int temp=ran.nextInt(100)+1;

arr[i]=temp;

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

if(arr[j]==temp){

i--;

break;

}

}

}

String str="您的隨機(jī)數(shù)是:";

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

str=str+arr[i]+" ";

}

System.out.println(str);

}

}

在線等一個(gè)java程序源代碼 急用!?。?/h2>

第一題

import java.util.Random;

import java.util.Scanner;

public class Guess{

public static void main(String[] args) {

int rightNum = new Random().nextInt(100) + 1;

Scanner scanner = new Scanner(System.in);

int input = 0;

do{

System.out.print("清猜數(shù)字(1-100)!");

input = scanner.nextInt();

if(input rightNum){

System.out.println("猜大了!");

}

else if(input rightNum){

System.out.println("猜小了!");

}

}while(input != rightNum);

System.out.println("猜對(duì)了" + rightNum);

}

}

第二題

import java.util.* ;

public class A{

public static void main(String args[]){

int i,j,k,temp;

int a[][]=new int[2][3];

a[0][0]=(int)(100*Math.random());

a[0][1]=(int)(100*Math.random());

a[0][2]=(int)(100*Math.random());

a[1][0]=(int)(100*Math.random());

a[1][1]=(int)(100*Math.random());

a[1][2]=(int)(100*Math.random());

for(j=0;j3;j++)

System.out.println("a[0]["+j+"]="+a[0][j]);

System.out.println(" ");

for(j=0;j3;j++)

System.out.println("a[1]["+j+"]="+a[1][j]);

System.out.println(" ");

for(i=0;i2;i++){

for(j=0;j2;j++){

for(k=j;k2;k++){

if(a[i][j]a[i][k+1]){

temp=a[i][j];

a[i][j]=a[i][k+1];

a[i][k+1]=temp;

}

}

}

}

System.out.println("第一行按從小到大排列:");

for(j=0;j3;j++){

System.out.println("a[0]["+j+"]="+a[0][j]);

}

System.out.println("第二行按從小到大排列:");

for(j=0;j3;j++)

System.out.println("a[1]["+j+"]=" +a[1][j]);

}

}

春春??還不快采納嘛

急求JAVA源代碼,小游戲或者別的

//這是個(gè)聊天程序, 在ECLIPSE 運(yùn)行 Client.java 就可以了。 連接是:localhost

//Server 代碼,

package message;

import java.io.*;

import java.net.*;

import java.util.*;

public class Server {

public static void main(String[] args) throws Exception{

System.out.print("Server");

ServerSocket socket=new ServerSocket(8888);

Vector v=new Vector();

while(true){

Socket sk=socket.accept();

DataInputStream in=new DataInputStream(sk.getInputStream());

DataOutputStream out=new DataOutputStream(sk.getOutputStream());

v.add(sk);

new ServerThread(in,v).start();

}

}

}

//ServerThread.java 代碼

package message;

import java.net.*;

import java.io.*;

import java.util.*;

public class ServerThread extends Thread{

DataInputStream in;

Vector all;

public ServerThread(DataInputStream in,Vector v){

this.in=in;

this.all=v;

}

public void run()

{

while(true)

{

try{

String s1=in.readUTF();

for(int i=0;iall.size();i++)

{

Object obj=all.get(i);

Socket socket=(Socket)obj;

DataOutputStream out=new DataOutputStream(socket.getOutputStream());

out.writeUTF(s1);

System.out.print(i);

out.flush();

}

System.out.print("Message send over!");

}catch(Exception e){e.printStackTrace();};

}

}

}

//ClientFrame.java 代碼

package message;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.net.*;

import java.io.*;

public class ClientFrame extends JFrame implements ActionListener{

JButton b1=new JButton ("SendMessage");

JButton b2=new JButton("Link Server");

JTextField t1=new JTextField(20);

JTextField t2=new JTextField(20);

JLabel l=new JLabel("輸入服務(wù)器名字:");

JTextArea area=new JTextArea(10,20);

JPanel p1=new JPanel();

JPanel p2=new JPanel();

JPanel p3=new JPanel();

JPanel p4=new JPanel();

Socket socket;

public ClientFrame()

{

this.getContentPane().add(p1);

p2.add(new JScrollPane(area));

p3.add(t1);

p3.add(b1);

p4.add(l);

p4.add(t2);

p4.add(b2);

p2.setLayout(new FlowLayout());

p3.setLayout(new FlowLayout());

p4.setLayout(new FlowLayout());

p1.setLayout(new BorderLayout());

p1.add("North",p2);

p1.add("Center",p3);

p1.add("South",p4);

b1.addActionListener(this);

b2.addActionListener(this);

this.pack();

show();

}

public void actionPerformed(ActionEvent e)

{

if(e.getActionCommand().equals("Link Server"))

{

try{

socket=new Socket(t2.getText(),8888);

b2.setEnabled(false);

JOptionPane.showMessageDialog(this, "Connection Success");

DataInputStream in=new DataInputStream(socket.getInputStream());

new ClientThread(in,area).start();

}

catch(Exception e1){

JOptionPane.showMessageDialog(this, "Connection Error");

e1.printStackTrace();};

}

else if(e.getActionCommand().equals("SendMessage"))

{

try{

DataOutputStream out=new DataOutputStream(socket.getOutputStream());

out.writeUTF(t1.getText());

t1.setText("");

}catch(Exception e1){e1.printStackTrace();};

}

}

}

//ClientThread.java 代碼

package message;

import java.net.*;

import java.io.*;

import javax.swing.*;

public class ClientThread extends Thread {

DataInputStream in;

JTextArea area;

public ClientThread(DataInputStream in,JTextArea area){

this.in=in;

this.area=area;

}

public void run()

{

while(true){

try{

String s=in.readUTF();

area.append(s);

}

catch(Exception e){e.printStackTrace();};

}

}

}

//Client.java代碼

package message;

public class Client {

/**

* @param args

*/

public static void main(String[] args) {

new ClientFrame();

}

}

// 每段代碼都是個(gè)類(lèi),不要弄在一個(gè)文件里。 運(yùn)行 Client.java

good luck to you!

分享名稱(chēng):java源代碼100例的簡(jiǎn)單介紹
路徑分享:http://aaarwkj.com/article24/hsohje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、手機(jī)網(wǎng)站建設(shè)、云服務(wù)器品牌網(wǎng)站制作、網(wǎng)站策劃微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)
日本女同一区二区高清| 青青草免费视频观看在线| 国产精品欧美一区久久| 2018在线不卡爱视频| 日本视频一曲二曲三曲四曲| 欧美亚洲国产另类第一页| 精品日韩欧美在线观看91| 亚州国产成人综合精品| 日本精品在线亚洲国产欧美| 99久久精品人妻少妇一| 欧美日韩中文字幕精品视频| 日本一区二区中文字幕在线| 国产精品成人大片在线播放| 国产三级三级三级三级| 精品亚洲一区二区三区四| 欧美高清一区二区三区精品| 插入内射视频在线观看| 日韩精品91一区二区| 日韩精品中文乱码在线观看| 美女诱惑丝袜国产国产av丝袜| 欧美性大片免费在线观看| 国产黄片a三级久久久久久| 日本一区二区国产在线| 九色综合一区二区三区| av影片免费网址大全| 亚洲成人大片免费在线观看| 久久国产精品久久国产精品| 日韩欧美国产精品专区| 亚洲青涩精品一区二区三区| 日本和亚洲的香蕉视频| 少妇激情一区二区三区免费视频| 中文字幕乱码日韩一二三区| 久久热在线观看免费高清| 免费黄色日韩在线观看| 日韩精品在线中文字幕| 女人高潮被爽到呻吟在线| 韩国av在线免费观看| 亚洲国产成在人网站天堂 | 亚洲成人av综合在线| 公侵犯人妻中文字幕一区| 亚洲一区二区日本久久|