重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

新手java编程短代码 java入门

用Java的if...else....和scanner还有且&&或 | | 写个简短的代码。速度

你好,很简短的代码

成都创新互联公司专注于上思企业网站建设,响应式网站设计,电子商务商城网站建设。上思网站建设公司,为上思等地区提供建站服务。全流程按需定制设计,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

package zhengze;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

String str = in.next();

if (str.equals("a")  str.equals("b")) {

} else if (str.equals("a") || str.equals("b")) {

} else {

}

}

}

希望可以帮助到你

java里升序和降序最简短的代码

直接调用jdk里面的方法Arrays.sort(args)方法。。。。

而且这个方法重载实现了多个参数,排序下标[N~M]位数字~倒叙,升序等等~

高分求一个运行在Eclipse环境下的java 扫雷游戏的初级代码 越小越好 越短越好 运行就好,就是初级就好了,

import java.awt.Button;

import java.util.Set;

// 每一个小方块类

public class Diamond extends Button {

private Diamond[] diamonds;

// 该小方块周围的八个方向上的小方块

private Diamond east;

private Diamond north;

private Diamond northEast;

private Diamond northWest;

private Diamond south;

private Diamond southEast;

private Diamond southWest;

private Diamond west;

private boolean isBomb;// 是否是雷

private boolean isChange;// 又没有被翻过

private int no;// 产生的方块的编号

// 持有所有小方块的引用,方便进行操作

public Diamond(Diamond[] diamonds) {

this.diamonds = diamonds;

}

// 按键时方块发生改变

public boolean change() {

this.isChange = true;// 说明已经翻过了

if(isBomb) {// 触雷

//this.setBackground(Color.red);

return true;

} else {// 不是雷,就显示周围雷的数目

//this.setLabel(this.getNearBombNo() + "");

this.setLabel(this.getNearBombNo() + "");

//if(this.getNearBombNo() == 0) {

// this.moveon();

//}

return false;

}

}

// 获得该小方块周围雷的数量

public int getNearBombNo() {

int no = 0;

if(this.northWest != null this.northWest.isBomb) no++;

if(this.north != null this.north.isBomb) no++;

if(this.northEast != null this.northEast.isBomb) no++;

if(this.east != null this.east.isBomb) no++;

if(this.southEast != null this.southEast.isBomb) no++;

if(this.south != null this.south.isBomb) no++;

if(this.southWest != null this.southWest.isBomb) no++;

if(this.west != null this.west.isBomb) no++;

return no;

}

// 获得该小方块周围的小方块

public Diamond getNearDimaond(int i) {

int index = -1;

switch (i) {

case 1:// 1表示西北,2,表示北,以此类推

index = no - 10;

if(index 1 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {

return null;

} else {

return diamonds[index];

}

case 2:

index = no - 9;

if(index 1) {

return null;

} else {

return diamonds[index];

}

case 3:

index = no - 8;

if(index 1 || no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72) {

return null;

} else {

return diamonds[index];

}

case 4:

index = no + 1;

if(no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {

return null;

} else {

return diamonds[index];

}

case 5:

index = no + 10;

if(index = 81 ||no == 9 || no == 18 || no == 27 || no == 36 || no == 45 || no == 54 || no == 63 || no == 72 || no == 81) {

return null;

} else {

return diamonds[index];

}

case 6:

index = no + 9;

if(index 81) {

return null;

} else {

return diamonds[index];

}

case 7:

index = no + 8;

if(index = 81 || no==1 || no == 10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {

return null;

} else {

return diamonds[index];

}

case 8:

index = no - 1;

if(no==1 || no==10 || no == 19 || no == 28 || no == 37 || no == 46 || no == 55 || no == 64 || no == 73) {

return null;

} else {

return diamonds[index];

}

}

return null;

}

// 递归,set是用来装已经翻过的小方块的,不然会死循环,为什么用set,因为set是不重复的

public void moveon(SetDiamond set) {

set.add(this);// 先把自己加上

if(this.getNorthWest() != null this.getNorthWest().isBomb == false) {

this.getNorthWest().change();

if(this.getNorthWest().getNearBombNo() == 0) {

if(set.contains(this.getNorthWest()) == false)

this.getNorthWest().moveon(set);

}

set.add(this.getNorthWest());

}

if(this.getNorth() != null this.getNorth().isBomb == false) {

this.getNorth().change();

if(this.getNorth().getNearBombNo() == 0) {

if(set.contains(this.getNorth()) == false)

this.getNorth().moveon(set);

}

set.add(this.getNorth());

}

if(this.getNorthEast() != null this.getNorthEast().isBomb == false) {

this.getNorthEast().change();

if(this.getNorthEast().getNearBombNo() == 0) {

if(set.contains(this.getNorthEast()) == false)

this.getNorthEast().moveon(set);

}

set.add(this.getNorthEast());

}

if(this.getEast() != null this.getEast().isBomb == false) {

this.getEast().change();

if(this.getEast().getNearBombNo() == 0) {

if(set.contains(this.getEast()) == false)

this.getEast().moveon(set);

}

set.add(this.getEast());

}

if(this.getSouthEast() != null this.getSouthEast().isBomb == false) {

this.getSouthEast().change();

if(this.getSouthEast().getNearBombNo() == 0) {

if(set.contains(this.getSouthEast()) == false)

this.getSouthEast().moveon(set);

}

set.add(this.getSouthEast());

}

if(this.getSouth() != null this.getSouth().isBomb == false) {

this.getSouth().change();

if(this.getSouth().getNearBombNo() == 0) {

if(set.contains(this.getSouth()) == false)

this.getSouth().moveon(set);

}

set.add(this.getSouth());

}

if(this.getSouthWest() != null this.getSouthWest().isBomb == false) {

this.getSouthWest().change();

if(this.getSouthWest().getNearBombNo() == 0) {

if(set.contains(this.getSouthWest()) == false)

this.getSouthWest().moveon(set);

}

set.add(this.getSouthWest());

}

if(this.getWest() != null this.getWest().isBomb == false) {

this.getWest().change();

if(this.getWest().getNearBombNo() == 0) {

if(set.contains(this.getWest()) == false)

this.getWest().moveon(set);

}

set.add(this.getWest());

}

}

/*public Diamond[] getDiamonds() {

return diamonds;

}*/

public Diamond getEast() {

return east;

}

public int getNo() {

return no;

}

public Diamond getNorth() {

return north;

}

public Diamond getNorthEast() {

return northEast;

}

public Diamond getNorthWest() {

return northWest;

}

public Diamond getSouth() {

return south;

}

public Diamond getSouthEast() {

return southEast;

}

public Diamond getSouthWest() {

return southWest;

}

public Diamond getWest() {

return west;

}

public boolean isBomb() {

return isBomb;

}

public boolean isChange() {

return isChange;

}

public void setBomb(boolean isBomb) {

this.isBomb = isBomb;

}

public void setChange(boolean isChange) {

this.isChange = isChange;

}

public void setDiamonds(Diamond[] diamonds) {

this.diamonds = diamonds;

}

public void setEast(Diamond east) {

this.east = east;

}

public void setNo(int no) {

this.no = no;

}

public void setNorth(Diamond north) {

this.north = north;

}

public void setNorthEast(Diamond northEast) {

this.northEast = northEast;

}

public void setNorthWest(Diamond northWest) {

this.northWest = northWest;

}

public void setSouth(Diamond south) {

this.south = south;

}

public void setSouthEast(Diamond southEast) {

this.southEast = southEast;

}

public void setSouthWest(Diamond southWest) {

this.southWest = southWest;

}

public void setWest(Diamond west) {

this.west = west;

}

}

JAVA编程 新手,写简单点

public static void main(String[] args) {

//控制台输入

Scanner scan = new Scanner(System.in);

//三次机会

for (int i = 2; i = 0; i--) {

//提示用户输入

System.out.println("请输入用户名");

//用户名

String userName = scan.next();

//提示用户输入

System.out.println("请输入密码");

//密码

String password = scan.next();

//如果输入正确,  break,结束循环

if("jim".equals(userName)  "123456".equals(password)) {

System.out.println("欢迎登录MyShopping系统");

break;

}

else {

if(i  0) {

System.out.println("密码错误,你还有"+i+"次机会!");

continue;

}

if(i == 0) {

System.out.println("密码错误,三次机会已用完!");

}

}

}

}

Java编程(写出程序代码)

写了一个代码,代码如下,可以进行参考

public class sum {

public static void main(String[] args) {

//创建一个Scanner的对象input

Scanner input = new Scanner(System.in); 

//提示用户输入数据 

System.out.print("请输入一个整数");

//将输入的值赋给n

int n = input.nextInt();

//定义变量接收计算后的和

int sum = 0;

//利用循环进行求和

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

sum+=i;

}

//输出最后的和

System.out.println("从0一直到"+n+"的所有整数的和是:"+sum);

}

}


本文名称:新手java编程短代码 java入门
链接地址:http://cqcxhl.cn/article/doocheo.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP