资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java命令代码大全 java命令详解

简单JAVA代码

输出错了!!!

留坝网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站设计等网站项目制作,到程序开发,运营维护。创新互联2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

第一个类的构造方法,请看

public tt(int b) {

b=x;

}

请问,你new出来tt这个类了,x有值了吧?

也就是说你在这里把x赋给了b,但是在第二个方法又无法用到b,也就是说,这个方法毫无用处

请将 b 和x的位置换换,同时,x为成员变量,不需要初始化给值的,是靠你传参数的。

第二,请看

public int cc(int b) {

b=x*2;

return b;

}

你可以完全把这个方法里的传参去掉,应为你的x是成员变量,改为

public int cc() {

return x*2;

}

然后在另外一个类里new出来tt,请看,我帮你修改了

Scanner a =new Scanner(System.in);

int b = a.nextInt();

tt cd =new tt(b);

int sd= cd.cc();

System.out.println(sb);

其实还可以改,

Scanner a =new Scanner(System.in);

tt cd =new tt(a.nextInt());

System.out.println(cd.cc());

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;j7;j++ ) {

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (yj) { //如果第二个按钮的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 (yj){ //如果第二个按钮的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 (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-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else { k=2; } //K=2说明通过了第二次验证

}

}

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

java代码尽量详细吧QAQ

你表述的不清楚。这个代码很简单,验证是否为空字符串,然后处理return里面调用的a方法的参数啊。

求JAVA编程代码

答案放在下面地址:

顺便给我踩下空间^-^

本小牛听了那六级大牛的建议后做了如下修改

第1题:

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class wangquanshu extends Applet implements ActionListener

{

int aa[]={6,28,496,8128,130816,2096128,33550336},bb[]={0,0,0,0,0,0,0};

//6=1+2+3

//28=1+2+4+7+14

//496=1+2+4+8+16+31+62+124+248

//8128=1+2+4+8+16+32+64+127+254+508+1016+2032+4064

//在1到40000000这么多数里,只有七个完全数,它们是:6,28,496,8128,130816,2096128,33550336

//java里int 32位 -2^31~2^31-1(大概20亿,应够了)

int j,q;

Label lab1;

TextField text1;

Label lab2;

TextField text2;

Button but;

public void init()

{ lab1=new Label("请输入上下限:");

text1=new TextField(8);

lab2=new Label(" - ");

text2=new TextField(8);

but=new Button("确定");

add(lab1);

add(text1);

add(lab2);

add(text2);

add(but);

but.addActionListener(this);

}

public void paint(Graphics g)

{int m=1; //用于控制输出自由数的位置

for(int n=0;n7;n++)

{g.drawString(" "+bb[n],10,50+m*20);

m++;

}

}

public void actionPerformed(ActionEvent e)

{int s=0;

int a=Integer.parseInt(text1.getText());

int b=Integer.parseInt(text2.getText());

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

{if(aa[j]aaa[j]b)

bb[j]=aa[j];

}

repaint();

}

}

第2题:

import java.io.*;

import java.text.DecimalFormat;

public class e

{public static void main(String args[])

{double ee=0;

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

{ee=ee+1/re(i);

}

DecimalFormat a=new DecimalFormat("0.00000000");

System.out.println(a.format(ee));

}

static double re(int n)

{if(n==0||n==1) return 1;

else return n*re(n-1);

}

}

急!!!关于Javac和Java命令,在程序代码中调用该命令编译和运行任意位置的文件

这个是这样的啊,有两种解决办法

一:把包去掉

二:运行时候加上这个

java wo/Helloworld1

为什么会出现这样的原因呢?

因为打包的时候已经把.class文件打包到wo的文件夹下去了

而java命令执行的时候是在当前目录下找.class文件,如果找不到就会出错

所以。。。。。

呵呵

给你做个示范

C:\javac -d . Helloworld1.java //打包

C:\java Helloworld1

Exception in thread "main" java.lang.NoClassDefFoundError: Helloworld1 (wrong na

me: wo/Helloworld1)

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(Unknown Source)

at java.security.SecureClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.defineClass(Unknown Source)

at java.net.URLClassLoader.access$000(Unknown Source)

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

Could not find the main class: Helloworld1. Program will exit.

成功后的是这样的:

C:\java wo/Helloworld1

Hello world!

讲的不是很多,但原理就这样的哦

java代码

import java.util.Arrays;

import java.util.HashSet;

public class RandomMid {

public static void main(String args[]) {

HashSetInteger hs = new HashSetInteger();

while (true) {

int a = (int) (Math.random() * (307-52)+52);

if (a = 52 a = 307) {

hs.add(a);

}

if (hs.size() == 3) {

break;

}

}

Object[] a = hs.toArray();

Arrays.sort(a);

Object num2[] = new Object[a.length];

for (int i = 0, j = 0; i a.length; i++, j++) {

num2[j] = a[i];

System.out.println("产生随机数"+(i+1)+":"+num2[i]);

}

System.out.println("中间值是: "+num2[1]);

}

}


当前文章:java命令代码大全 java命令详解
URL标题:http://cdkjz.cn/article/dossjgs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220