當前位置:首頁 » 編程語言 » java代

java代

發布時間: 2022-04-22 06:38:00

① 什麼是java源代碼 怎麼查看

不知道你說的是瀏覽器的還是什麼的,
如果是瀏覽器的那麼簡單找到工具-查看源代碼,你就能看見代碼了,
還有一個就是被編譯成class文件的java用反編譯工具可以看到源代碼,
如果以上都不是你想要的答案,那麼你所說的代碼就是程序員寫好的代碼文件

② Java求程序代碼

按照你的要求編寫的Java程序如下

import java.util.Scanner;

public class S{

public static void main(String[] args){

int n=5;

int[] a=new int[n];

System.out.print("請輸入"+n+"個正整數:");

Scanner sc=new Scanner(System.in);

for(int i=0;i<n;i++){

a[i]=sc.nextInt();

}

System.out.print("其中的偶數為:");

for(int i=0;i<n;i++){

if(a[i]%2==0){

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

}

}

}

}

③ 求一個簡單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 代碼

連連看java源代碼
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; //分別記錄兩次被選中的按鈕
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;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ連連看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再來一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins<=15;twins++) {
randoms=(int)(Math.random()*25+1);
for(int alike=1;alike<=2;alike++) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i<=6;i++) {
for(int j=0;j<=5;j++) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n++;
}
}
}
n=n-1;
this.grid=grid;
while(n>=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //這里一定要將按鈕點擊信息歸為初始
init();
for(int i = 0;i < 6;i++){
for(int j = 0;j < 5;j++ ){
if(grid[i+1][j+1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsg && secondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情況下能不能消去。仔細分析,不一條條注釋
if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判斷是否相鄰
remove();
}
else{
for (j=0;j<7;j++ ) {
if (grid[x0][j]==0){ //判斷第一個按鈕同行哪個按鈕為空
if (y>j) { //如果第二個按鈕的Y坐標大於空按鈕的Y坐標說明第一按鈕在第二按鈕左邊
for (i=y-1;i>=j;i-- ){ //判斷第二按鈕左側直到第一按鈕中間有沒有按鈕
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1說明通過了第一次驗證
}
if (k==1) {
linePassOne();
}
}
if (y<j){ //如果第二個按鈕的Y坐標小於空按鈕的Y坐標說明第一按鈕在第二按鈕右邊
for (i=y+1;i<=j ;i++ ){ //判斷第二按鈕左側直到第一按鈕中間有沒有按鈕
if (grid[x][i]!=0){
k=0;
break;
}
else { k=1; }
}
if (k==1){
linePassOne();
}
}
if (y==j ) {
linePassOne();
}
}
if (k==2) {
if (x0==x) {
remove();
}
if (x0<x) {
for (n=x0;n<=x-1;n++ ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 && n==x-1) {
remove();
}
}
}
if (x0>x) {
for (n=x0;n>=x+1 ;n-- ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 && n==x+1) {
remove();
}
}
}
}
}
for (i=0;i<8;i++ ) { //列
if (grid[i][y0]==0) {
if (x>i) {
for (j=x-1;j>=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x<i) {
for (j=x+1;j<=i;j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x==i) {
rowPassOne();
}
}
if (k==2){
if (y0==y) {
remove();
}
if (y0<y) {
for (n=y0;n<=y-1 ;n++ ) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 && n==y-1) {
remove();
}
}
}
if (y0>y) {
for (n=y0;n>=y+1 ;n--) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 && n==y+1) {
remove();
}
}
}
}
}
}
}
public void linePassOne(){
if (y0>j){ //第一按鈕同行空按鈕在左邊
for (i=y0-1;i>=j ;i-- ){ //判斷第一按鈕同左側空按鈕之間有沒按鈕
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2說明通過了第二次驗證
}
}
if (y0<j){ //第一按鈕同行空按鈕在與第二按鈕之間
for (i=y0+1;i<=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0>i) {
for (j=x0-1;j>=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0<i) {
for (j=x0+1;j<=i ;j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
public void remove(){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==newlyButton){
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation=false;
init();
}
if(e.getSource()==exitButton)
System.exit(0);
if(e.getSource()==resetButton)
reload();
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
lianliankan llk = new lianliankan();
llk.randomBuild();
llk.init();
}
}

//old 998 lines
//new 318 lines

⑤ java代碼

  • *Createdbyy0non2017/4/17.

  • *1.輸出控制台傳遞的默認參數

  • */

  • publicclassJavaDay001_1{

  • publicstaticvoidmain(String[]args){

  • System.out.println(args);

  • }

  • }

  • /**

  • *Createdbyy0non2017/4/17.

  • *2.編程求表達式的結果

  • */

  • publicclassJavaDay001_2{

  • publicstaticvoidmain(String[]args){

  • System.out.println("128&129="+(128&129));

  • System.out.println("56|32="+(56|32));

  • System.out.println("27^123="+(27^123));

  • }

  • }

  • /**

  • *Createdbyy0non2017/4/17.

  • *3.從鍵盤上輸入3個數,求出這三個數字中的最大值,並將最大值輸出

  • */

  • importjava.util.Scanner;

  • publicclassJavaDay001_3{

  • publicstaticvoidmain(String[]args){

  • System.out.println("請輸入3個數:");

  • Scannerscanner=newScanner(System.in);

  • intnNumA=scanner.nextInt();

  • intnNumB=scanner.nextInt();

  • intnNumC=scanner.nextInt();

  • intnMax=0;

  • if(nNumA>=nNumB&&nNumA>=nNumC)

  • {

  • nMax=nNumA;

  • }

  • elseif(nNumB>=nNumC&&nNumB>=nNumA)

  • {

  • nMax=nNumB;

  • }

  • elseif(nNumC>=nNumA&&nNumC>=nNumB)

  • {

  • nMax=nNumC;

  • }

  • else

  • {

  • System.out.println("無法比較!");

  • }

  • System.out.println("Max="+nMax);

  • }

  • }

  • /**

  • *Createdbyy0non2017/4/17.

  • *4.編寫萬年歷小程序

  • *輸出結果:

  • *請輸入年:2016

  • *請輸入月:6

  • *2016年非潤年

  • *2016年6月份的天數是30

  • */

  • importcom.sun.webkit.BackForwardList;

  • importjava.util.Scanner;

  • publicclassJavaDay001_4{

  • publicstaticvoidmain(String[]args){

  • System.out.println("請輸入年:");

  • Scannerscanner=newScanner(System.in);

  • intnYear=scanner.nextInt();

  • System.out.println("請輸入月:");

  • intnMounth=scanner.nextInt();

  • intnflag=0;

  • if(nYear%4==0)

  • {

  • if(nYear%100==0)

  • {

  • if(nYear%400==0)

  • {

  • nflag=1;

  • System.out.println(nYear+"年是潤年");

  • }

  • else

  • {

  • System.out.println(nYear+"年不是潤年");

  • }

  • }

  • else

  • {

  • nflag=1;

  • System.out.println(nYear+"年不是潤年");

  • }

  • }

  • else

  • {

  • System.out.println(nYear+"年不是潤年");

  • }

  • //判斷2016年月份的天數

  • if(nMounth==1

  • ||nMounth==3

  • ||nMounth==5

  • ||nMounth==7

  • ||nMounth==8

  • ||nMounth==10

  • ||nMounth==12)

  • {

  • System.out.println(nYear+"年"+nMounth+"月份的天數是:31");

  • }

  • elseif(nMounth==4

  • ||nMounth==6

  • ||nMounth==9

  • ||nMounth==11)

  • {

  • System.out.println(nYear+"年"+nMounth+"月份的天數是:30");

  • }

辛苦,望採納!老鐵

⑥ JAVA代碼

package mainjava;

public class Doubleqiu {

public static void main(String[] args)
{
int array[] = new int[7];
boolean flag = false;
for(int i = 0; i <6;i++)
{
flag = true;
while(flag){
int numRed = (int) (Math.random()*33+1);
for(int j = 0;j<array.length;j++)
{
if(numRed == array[j])
{
flag = true;
break;
}
flag = false;
}
array[i] = numRed;
}
}
int numBlue = (int) (Math.random()*16+1);
array[6] = numBlue;
for(int i = 0;i<array.length;i++)
{
System.out.print(array[i]+" ");
}
}
}
如能幫到你,望隨手採納謝謝,有問題可追問。
用集合的方法:
package mainjava;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Doubleqiu {

public static int count = 0;
public static void main(String[] args)
{

List<Integer> list=new ArrayList<Integer>();
List<Integer> list1=new ArrayList<Integer>();
while(list.size() < 6)
{
int numRed = (int) (Math.random()*33+1);
if(!list.contains(numRed))
{
list.add(numRed);
}

}
list.add((int) (Math.random()*16+1));

System.out.println(list);
System.out.println(list.size());

Scanner sc = new Scanner(System.in);

for(int i = 0;i<7;i++)
{
list1.add(sc.nextInt());
}

System.out.println(list1);

for(int i=0;i<list.size()-1;i++){
for(int j=0;j<list1.size()-1;j++){
//判斷值是否相同
if(list.get(i).equals(list1.get(j))){
count++;//相同count加一
}
}
}
if(list.get(6).equals(list1.get(6))){
count++;//相同count加一
}

if(count == 7)
{
System.out.println("恭喜中獎!");
}else{
System.out.println("很遺憾,本次未中獎!");
}
}
}

⑦ java代碼 什麼意思

首先理解public boolean addBook(Book book )這句話的含義是創建一個大家都能使用的公共方法(public的作用),該方法返回一個布爾類型的值(boolean的作用),該方法的名字是addBooke(調用方法需要名字啊,沒名字怎麼用它),這個方法需要的參數是一個Book類型的對象book(Book book的作用);
每一個方法都有一個方法簽名:方法簽名就是方法名和參數列表(在這里就是 addBook(Book book))通過方法簽名我們就能正確的找到並執行該方法;
方法名,顧名思義就是方法的名字,一個類中可以有很多相同方法名的方法,就拿addBook來所,是添加書,添加書的渠道很多,可以通過書名添加,也可以通過id添加,只不過執行的邏輯和需要的參數不同;所以一個類中可以有很多的同名方法,那麼程序如何區分這些方法呢?那就是通過方法簽名的另一個元素——參數列表,在java中稱方法名相同,參數列表不同的情況為方法的重載;

這位大哥問的就是參數列表的問題,參數列表中需要的是參數的數據類型,和一個引用來臨時在方法中保存用戶給的數據;這里Book就是數據類型,book就是一個臨時的引用在方法體內可以代表用戶給的數據的;這里有需要有棧楨和堆的概念了,在沒有這些基礎知識的時候我們只要知道,book是一個引用,在方法體中我么可以使用book來操作一個不屬於我們的外部對象;

純手打望採納;

⑧ 怎麼寫java代碼

只要自己的電腦安裝了jdk環境,任何地方都可以進行java代碼的編寫的,記事本也可以。

⑨ 簡單的java代碼

equals比較的是內容,
==比較的是對象,
str1.leader == "不是"語句中,str1.leader和「不是」是兩個不同的String對象,所以永遠都是false。(String不是基本數據類型,是引用對象)

例如:
String a = "abc";
String b = a;
String c = "abc";
System.out.println(a==b);//true
System.out.println(a==c);//false
// 但是這樣都是true
System.out.println(a.equals(b));//true
System.out.println(a.equals(c));//true

⑩ java代碼解讀

第一個if是判斷searchkey是不是空的,如果不是空的,就追加到name欄位作為查詢條件,like模糊查詢
接著第二個if判斷如果status的值不為空,就追加到status作為條件
如果status為空,走else分支,從userContext中獲取到employee對象,接著判斷,如果它的角色不是manager的話
把這個對象的id拿出來,作為seller.Id的條件進行查詢

熱點內容
內置存儲卡可以拆嗎 發布:2025-05-18 04:16:35 瀏覽:333
編譯原理課時設置 發布:2025-05-18 04:13:28 瀏覽:376
linux中進入ip地址伺服器 發布:2025-05-18 04:11:21 瀏覽:610
java用什麼軟體寫 發布:2025-05-18 03:56:19 瀏覽:31
linux配置vim編譯c 發布:2025-05-18 03:55:07 瀏覽:107
砸百鬼腳本 發布:2025-05-18 03:53:34 瀏覽:941
安卓手機如何拍視頻和蘋果一樣 發布:2025-05-18 03:40:47 瀏覽:739
為什麼安卓手機連不上蘋果7熱點 發布:2025-05-18 03:40:13 瀏覽:802
網卡訪問 發布:2025-05-18 03:35:04 瀏覽:510
接收和發送伺服器地址 發布:2025-05-18 03:33:48 瀏覽:371