新聞中心
JAVA 請(qǐng)寫(xiě)出全部代碼?
import?java.util.Arrays;
創(chuàng)新互聯(lián)公司是專(zhuān)業(yè)的谷城網(wǎng)站建設(shè)公司,谷城接單;提供成都網(wǎng)站制作、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行谷城網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
import?java.util.Scanner;
public?class?Test?{
public?static?void?main(String[]?args)?{
System.out.println("請(qǐng)依次輸入三個(gè)整數(shù):a,b,c(以空格隔開(kāi))");
Scanner?sc?=?new?Scanner(System.in);
int?[]arr?=?new?int[3];
arr[0]?=?sc.nextInt();
arr[1]?=?sc.nextInt();
arr[2]?=?sc.nextInt();
Arrays.sort(arr);
System.out.println("最大值為:"?+?arr[2]);
}
}
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 + " ");
}
}
}
}
}
是好使的 但是我沒(méi)找到畫(huà)五角星有什么規(guī)律(五角星好象不是正規(guī)圖形吧?)如果還有什么要求的話 補(bǔ)充問(wèn)題(如果是用*填充所有的東西 不包括 “ ”的話 我可以重新再給你寫(xiě)一個(gè))
JAVA編譯題(給個(gè)全部的代碼)
參考代碼MaxArray類(lèi)
public?class?MaxArray{
public?static?int?getMaxNum(int[]?arry){
int?max?=?arry[0];//假設(shè)數(shù)組第一個(gè)數(shù)最大
for?(int?i?=?1;?i??arry.length;?i++)?{
if(arry[i]max){//如果max不是最大的數(shù)字,那么久替換成當(dāng)前的arry[i]
max?=?arry[i];
}
}
return?max;
}
public?static?boolean?isNumInArray(int?num,int[]?arry){
boolean?boo?=?false;//假設(shè)num不在arry中
for?(int?i?=?0;?i??arry.length;?i++)?{
if(num==arry[i]){//如果num在arry中
boo?=?true;//那么boo的值為true
break;//發(fā)現(xiàn)num中其中了,就不用一直找了,break跳出循環(huán)
}
}
return?boo;//返回boo的值
}
}
參考代碼Test類(lèi)
import?java.util.Scanner;
public?class?Test?{
public?static?void?main(String[]?args)?{
System.out.print("請(qǐng)輸入數(shù)組的元素個(gè)數(shù)");
Scanner?input?=?new?Scanner(System.in);
int?n?=?Integer.parseInt(input.nextLine().trim());
//input.nextLine()讀取一行,
//trim()去掉空白,比如??3?--3
//Integer.parseInt從字符串解析成為整數(shù)
int[]?arry?=?new?int[n];//創(chuàng)建的整數(shù)數(shù)組
for?(int?i?=?0;?i??arry.length;?i++)?{
System.out.print("請(qǐng)輸入數(shù)組第"+(i+1)+"個(gè)元素:");
arry[i]?=?Integer.parseInt(input.nextLine().trim());
}
int?maxNum?=?MaxArray.getMaxNum(arry);//通過(guò)類(lèi)名直接調(diào)用靜態(tài)方法
System.out.println("數(shù)組中的最大值:"+maxNum);
System.out.print("請(qǐng)輸入一個(gè)整數(shù):");
int?num?=?Integer.parseInt(input.nextLine().trim());
boolean?boo?=?MaxArray.isNumInArray(num,arry);
if(boo){
System.out.println("整數(shù)"+num+"在數(shù)組中");
}else{
System.out.println("整數(shù)"+num+"不在數(shù)組中");
}
input.close();
}
}
運(yùn)行測(cè)試
請(qǐng)輸入數(shù)組的元素個(gè)數(shù)3
請(qǐng)輸入數(shù)組第1個(gè)元素:26
請(qǐng)輸入數(shù)組第2個(gè)元素:18
請(qǐng)輸入數(shù)組第3個(gè)元素:92
數(shù)組中的最大值:92
請(qǐng)輸入一個(gè)整數(shù):18
整數(shù)18在數(shù)組中
Java語(yǔ)言編寫(xiě)代碼
代碼如下
/**
*?Author:?zhyx
*?Date:2017/11/30
*?Time:8:56
*/
public?abstract?class?Contailner?{
double?r;
abstract?double?volume();
}
/**
*?Author:?zhyx
*?Date:2017/11/30
*?Time:8:57
*/
public?class?Cube?extends?Contailner?{
public?Cube(double?r)?{
this.r=r;
}
@Override
double?volume()?{
return?r*r*r;
}
}
/**
*?Author:?zhyx
*?Date:2017/11/30
*?Time:9:01
*/
public?class?Sphere?extends?Contailner?{
public?Sphere(double?r)?{
this.r=r;
}
@Override
double?volume()?{
return?4/3*Math.PI*r*r*r;
}
}
/**
*?Author:?zhyx
*?Date:2017/11/30
*?Time:9:02
*/
public?class?Tiji?{
public?static?void?main(String[]?args)?{
Cube?cube=new?Cube(4);
System.out.println("立方體體積為:"+cube.volume());
Sphere?sphere=?new?Sphere(4);
System.out.println("球體體積為:"+sphere.volume());
}
}
JAVA的編譯器有哪些?
推薦Jcreator,它對(duì)于初學(xué)者是個(gè)很好的開(kāi)發(fā)工具,又小運(yùn)行也很快。它要用到JDK,大的IDE有JBuilder,netbean,sun stdio,eclipse。
編譯器就是將"一種語(yǔ)言(通常為高級(jí)語(yǔ)言)"翻譯為"另一種語(yǔ)言(通常為低級(jí)語(yǔ)言)"的程序。一個(gè)現(xiàn)代編譯器的主要工作流程:源代碼 (source code) → 預(yù)處理器 (preprocessor) → 編譯器 (compiler) → 目標(biāo)代碼 (object code) → 鏈接器 (Linker) → 可執(zhí)行程序 (executables)
高級(jí)計(jì)算機(jī)語(yǔ)言便于人編寫(xiě),閱讀交流,維護(hù)。機(jī)器語(yǔ)言是計(jì)算機(jī)能直接解讀、運(yùn)行的。編譯器將匯編或高級(jí)計(jì)算機(jī)語(yǔ)言源程序(Source program)作為輸入,翻譯成目標(biāo)語(yǔ)言(Target language)機(jī)器代碼的等價(jià)程序。源代碼一般為高級(jí)語(yǔ)言 (High-level language), 如Pascal、C、C++、Java、漢語(yǔ)編程等或匯編語(yǔ)言,而目標(biāo)則是機(jī)器語(yǔ)言的目標(biāo)代碼(Object code),有時(shí)也稱(chēng)作機(jī)器代碼(Machine code)。
對(duì)于C#、VB等高級(jí)語(yǔ)言而言,此時(shí)編譯器完成的功能是把源碼(SourceCode)編譯成通用中間語(yǔ)言(MSIL/CIL)的字節(jié)碼(ByteCode)。最后運(yùn)行的時(shí)候通過(guò)通用語(yǔ)言運(yùn)行庫(kù)的轉(zhuǎn)換,編程最終可以被CPU直接計(jì)算的機(jī)器碼(NativeCode)。
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];//游戲按鈕數(shù)組
JButton exitButton,resetButton,newlyButton; //退出,重列,重新開(kāi)始按鈕
JLabel fractionLable=new JLabel("0"); //分?jǐn)?shù)標(biāo)簽
JButton firstButton,secondButton; //分別記錄兩次被選中的按鈕
int grid[][] = new int[8][7];//儲(chǔ)存游戲按鈕位置
static boolean pressInformation=false; //判斷是否有按鈕被選中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戲按鈕的位置坐標(biāo)
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("再來(lái)一局");
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; //這里一定要將按鈕點(diǎn)擊信息歸為初始
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() { //相同的情況下能不能消去。仔細(xì)分析,不一條條注釋
if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判斷是否相鄰
remove();
}
else{
for (j=0;j7;j++ ) {
if (grid[x0][j]==0){ //判斷第一個(gè)按鈕同行哪個(gè)按鈕為空
if (yj) { //如果第二個(gè)按鈕的Y坐標(biāo)大于空按鈕的Y坐標(biāo)說(shuō)明第一按鈕在第二按鈕左邊
for (i=y-1;i=j;i-- ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒(méi)有按鈕
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1說(shuō)明通過(guò)了第一次驗(yàn)證
}
if (k==1) {
linePassOne();
}
}
if (yj){ //如果第二個(gè)按鈕的Y坐標(biāo)小于空按鈕的Y坐標(biāo)說(shuō)明第一按鈕在第二按鈕右邊
for (i=y+1;i=j ;i++ ){ //判斷第二按鈕左側(cè)直到第一按鈕中間有沒(mé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 (x0x) {
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 (x0x) {
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;i8;i++ ) { //列
if (grid[i][y0]==0) {
if (xi) {
for (j=x-1;j=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
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 (y0y) {
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 (y0y) {
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 (y0j){ //第一按鈕同行空按鈕在左邊
for (i=y0-1;i=j ;i-- ){ //判斷第一按鈕同左側(cè)空按鈕之間有沒(méi)按鈕
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2說(shuō)明通過(guò)了第二次驗(yàn)證
}
}
if (y0j){ //第一按鈕同行空按鈕在與第二按鈕之間
for (i=y0+1;i=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1;j=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0i) {
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
新聞標(biāo)題:Java編譯器代碼大全 java中文編譯器
本文來(lái)源:http://fisionsoft.com.cn/article/hjpejh.html