2008年3月25日
摘要:
1import java.util.Scanner;
2
3public class StuManager {
4
5 /** *//**
6 *&...
阅读全文
写了一半 现在只能下棋 还不能判断
package day04;
import java.util.Scanner;
public class FiveChess {
public static void main(String[] args) {
char[][] state=new char[14][14];
for(int i=0;i<state.length;i++){
for(int j=0;j<state[i].length;j++){
state[i][j]='*';
}
}
boolean isBlack=true;//当前是黑方下子
Scanner sca=new Scanner(System.in);
printState(state);
while(true){
System.out.println("请"+(isBlack?"黑":"白")+"方下子:");
String input=sca.next();
if(input.equals("exit")){
break;
}
int x=input.charAt(0)-'a';
int y=input.charAt(1)-'a';
if(state[x][y]=='@' || state[x][y]=='O'){//该位置已经有棋子了
System.out.println("该位置已经有棋子,请重新指定坐标!");
continue;
}
state[x][y]=(isBlack?'@':'O');
printState(state);
if(isWin(state,isBlack,x,y)){
System.out.println((isBlack?"黑":"白")+"方获胜!");
break;
}
isBlack=!isBlack;
}
}
public static void printState(char[][] state){
for(int i=0;i<state.length;i++){//输出每一行的内容
System.out.print((char)('a'+i)+" ");//输出行坐标(左边的字母)
for(int j=0;j<state[i].length;j++){//输出该行的内容
System.out.print(state[i][j]+" ");
}
System.out.print("\n");//输出换行符
}
System.out.print(" ");//输出第一行开头的空格
for(int i=0;i<state[0].length;i++){//输出第一行的所有字母
System.out.print((char)('a'+i)+" ");
}
System.out.print("\n");//输出换行符
}
public static boolean isWin(char[][] state,boolean isBlack,int x,int y){
//char c=isBlack?'@':'O';
return isShuipingWin(state,isBlack,x,y) || isChuizhiWin(state,isBlack,x,y) ||
isZuoXieWin(state,isBlack,x,y) || isYouXieWin(state,isBlack,x,y);
}
public static boolean isShuipingWin(char[][] state,boolean isBlack,int x,int y){
//?????
return false;
}
public static boolean isChuizhiWin(char[][] state,boolean isBlack,int x,int y){
//?????
return false;
}
public static boolean isZuoXieWin(char[][] state,boolean isBlack,int x,int y){
//??????
return false;
}
public static boolean isYouXieWin(char[][] state,boolean isBlack,int x,int y){
//??????
return false;
}
}
import java.util.*;
public class Bool
{
public static void main(String args[])
{
Random rand= new Random ();
int i=rand.nextInt()%100;
int j=rand.nextInt()%100;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("i>j is "+(i>j));
System.out.println("i<j is "+(i<j));
System.out.println("i>=j is "+(i>=j));
System.out.println("i<=j is "+(i<=j));
System.out.println("i==j is "+(i==j));
System.out.println("i!=j is "+(i!=j));
System.out.println("(i<10)&&(j<10) is "+((i<10)&&(j<10)));
System.out.println("(i>10)||(j>10) is "+((i>10)||(j>10)));
}
}
public class guanxi
{
public static void main (String args[])
{
float a=10.0f;
double b=10.0;
if(a==b)
{
System.out.println("a和b相等");
}
else
{
System.out.println("a和b不相等");
}
}
}
public class autoinc
{
public static void main (String[] args){
int i= 1;
System.out.println("i:"+i);
System.out.println("++i:"+ ++i);
System.out.println("i++:"+ i++);
System.out.println("i:"+i);
System.out.println("--i:"+ --i);
System.out.println("i--:"+ i--);
System.out.println("i:"+i);
}
}
public class SimpleTypes {
public static void main (String args [])
{
byte b=0x55;
short s=0x55ff;
int i=1000000;
char c='c';
float f=0.23f;
double d=0.7E-3;
boolean bool=true;
System.out.println("b="+b);
System.out.println("s="+s);
System.out.println("i="+i);
System.out.println("c="+c);
System.out.println("f="+f);
System.out.println("d="+d);
System.out.println("bool="+bool);
}
}
/**
* @算术运算符的运算
*/
public class suanshu{
public static void main (String args[])
{
int a=5+4;
int b=a*2;
int c=b/4;
int d=b-c;
int e=-d;
int f=e%4;
double g=18.4;
double h=g%4;
int i=3;
int j=i++;
int k=++i;
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
System.out.println("d="+d);
System.out.println("e="+e);
System.out.println("f="+f);
System.out.println("g="+g);
System.out.println("h="+h);
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("k="+k);
}
}