当前位置:首页 » 编程语言 » 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 浏览:374
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 浏览:105
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:940
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:737
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:801
网卡访问 发布:2025-05-18 03:35:04 浏览:507
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:369