1百分制分数到等级分数

package pm;

public class SwitchTest {

//编写程序,实现从百分制分数到等级分数的转换

//

//>=90 A

//80~89 B

//70~79 C

//60~69 D

//<60 E

publicstatic void main(String[] args) {

ints=87;

switch(s/10){

case 10 :System.out.println("A");break;

case9 :System.out.println("A");break;

case8 :System.out.println("B");break;

case7 :System.out.println("c");break;

case6 :System.out.println("D");break;

default:System.out.println("E");break;

}

}

}

2成法口诀阵形

package pm;

public class SwitchTest{

publicstatic void main(String[] args){

for(int i=1;i<=9;i++){

for(int j=1;j<=i;j++){

System.out.print(j+"*"+i+"="+(i*j)+"\t");

}

System.out.println();

}

}

}

3华氏和摄氏的转换法

package pm;

import java.util.Scanner;

public class SwitchTest {

publicstatic void main(String[] args) {

Scannersc=new Scanner(System.in);

while(true) {

System.out.println("请输入要转换的温度类型:C 或 F");

Strings = sc.next().trim();

if("c".equalsIgnoreCase(s)) {

//做摄氏向华摄的转换

System.out.println("请输入要转换摄氏的温度:..");

doubledb = sc.nextDouble();

doubledb2 = (db * 9 / 5) + 32;

System.out.println("对应的华氏温度:" + db2 +"F");

}else if ("f".equalsIgnoreCase(s)) {

//做华摄向摄氏的转换

System.out.println("请输入要转换华氏的温度:..");

doubledb = sc.nextDouble();

doubledb2 = (db - 32) * 5 / 9;

System.out.println("对应的摄氏温度:" + Math.round(db2) +"C");

}elseif("exit".equalsIgnoreCase(s)){

break;

}

}

}

}

package pm;

import java.util.Scanner;

public class SwitchTest{

publicstatic void main(String[] args) {

Scannersc=new Scanner(System.in);

booleanflag=true;

while(flag) {

System.out.println("请输入要转换的温度,如:50c或100f");

Stringstr = sc.nextLine().trim();

if(str.endsWith("c") || str.endsWith("C")) {

//做摄氏向华摄的转换  30c

Stringst = str.substring(0, str.length() - 1);

doubledb = Double.parseDouble(st);//[0,2)

//2double db=Double.valueOf(st).doubleValue();

doubledb2 = (db * 9 / 5) + 32;

System.out.println("对应的华氏温度:" + db2 +"F");

}else if (str.endsWith("f") || str.endsWith("F")) {

//做华摄向摄氏的转换

Stringst = str.substring(0, str.length() - 1);

doubledb = Double.parseDouble(st);//[0,2)

//2double db=Double.valueOf(st).doubleValue();

doubledb2 = (db - 32) * 5 / 9;

System.out.println("对应的摄氏温度:" + Math.round(db2) +"C");

}elseif("exit".equalsIgnoreCase(str)){

flag=false;

}

}

}

}

4三个数的最大数

package pm;

public class SwitchTest {

publicstatic void main(String[] args) {

inta=1,b=2,c=3,d=0;

d=a>b?a:b;

d=a>b?(a>c?a:c):(b>c?b:c);

System.out.println("最多数为:"+d);

}

}

5简单计算器的小程序

package one;

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class Jsq implements ActionListener{

privateJFrame frame;

privateJButton[] bus;

privateJTextField jtx;

privateJButton bu;

privatechar[] strs;

privateString d_one = "";

privateString operator;

publicstatic void main(String[] args) {

newJsq();

}

/*利用构造进行实例化 */

publicJsq() {

frame= new JFrame("计算器");

jtx= new JTextField(14);

bus= new JButton[16];

strs= "789/456*123-0.+=".toCharArray();

for(int i = 0; i < 16; i++) {

bus[i]= new JButton(strs[i] + "");

bus[i].addActionListener(this);

}

bu= new JButton("C");

bu.addActionListener(this);

init();

}

/*GUI 初始化 */

publicvoid init() {

JPaneljp1 = new JPanel();

jp1.add(jtx);

jp1.add(bu);

frame.add(jp1,BorderLayout.NORTH);

JPaneljp2 = new JPanel();

jp2.setLayout(newGridLayout(4, 4));

for(int i = 0; i < 16; i++) {

jp2.add(bus[i]);

}

frame.add(jp2,BorderLayout.CENTER);

frame.pack();

frame.setLocation(300,400);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

/*事件的处理 */

publicvoid actionPerformed(ActionEvent arg0) {

/*获取输入字符*/

Stringconn = arg0.getActionCommand();

/*清除计算器内容*/

if("C".equals(conn)) {

d_one= "";

operator= "";

jtx.setText("");

return;

}

/*暂未实现该功能*/

if(".".equals(conn)){

return;

}

/*记录运算符,保存运算数字*/

if(("+-*/".indexOf(conn)) != -1) {

if("".equals(d_one)&& "".equals(jtx.getText())) return;

d_one= jtx.getText();

operator= conn;

jtx.setText("");

return;

}

/*计算结果*/

if("=".equals(conn)) {

if("".equals(d_one)&& "".equals(jtx.getText())) return;

doubledb = 0;

if("+".equals(operator)) {

db= Double.parseDouble(d_one)

+Double.parseDouble(jtx.getText());

jtx.setText(db+ "");

}

if("-".equals(operator)) {

db= Double.parseDouble(d_one)

-Double.parseDouble(jtx.getText());

jtx.setText(db+ "");

}

if("*".equals(operator)) {

db= Double.parseDouble(d_one)

*Double.parseDouble(jtx.getText());

jtx.setText(db+ "");

}

if("/".equals(operator)) {

db= Double.parseDouble(d_one)

/Double.parseDouble(jtx.getText());

jtx.setText(db+ "");

}

d_one= db + "";

return;

}

//界面显示

jtx.setText(jtx.getText()+ conn);

}

}

6三角形图案

package pm;

public class SwitchTest{

publicstatic void main(String[] args){

int n=5;

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

for(int j=0;j<n-i;j++){

System.out.print(" ");

}

for(int k=0;k<2*i-1;k++){

System.out.print("*");

}

System.out.println();

}

}

}

7输出输入的姓名

package pm;

import java.util.Scanner;

public class SwitchTest{

publicstatic void main(String[] args){

String name=null;

Scanner sca=new Scanner (System.in);

char firstChar;

do{

System.out.println("pleaseinput your name");

name=sca.nextLine();

firstChar=name.charAt(0);

}while(!(firstChar>='a' &&firstChar<='z' ||

firstChar>='A'&& firstChar<='Z'));

System.out.println("OK!your name is:"+name);

}

}

8一小时倒计时小程序

package pm;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

public class SwitchTest {

privateJFrame frame;

private  JLabel jl1;

privateJLabel jl2;

privateJLabel jl3;

/*主方法*/

publicstatic void main(String[] args) {

newSwitchTest().getTime();

}

/*倒计时的主要代码块*/

private  void getTime(){

longtime=1*3600;

longhour =0 ;

long  minute =0 ;

longseconds=0;

while(time>=0){

hour=time/3600;

minute=(time-hour*3600)/60;

seconds=time-hour*3600-minute*60;

jl1.setText(hour+"时");

jl2.setText(minute+"分");

jl3.setText(seconds+"秒");

try{

Thread.sleep(1000);

}catch (InterruptedException e) {

e.printStackTrace();

}

time--;

}

}

/*构造 实现界面的开发 GUI */

publicSwitchTest(){

frame= new JFrame("倒计时");

jl1= new JLabel();

jl2= new JLabel();

jl3= new JLabel();

init();

}

/*组件的装配*/

privatevoid init(){

JPaneljp=new JPanel();

jp.add(jl1);

jp.add(jl2);

jp.add(jl3);

frame.add(jp);

frame.setVisible(true);

frame.setLocation(300,400);

frame.setSize(300,200);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

9棋盘图案

public class Sjx{

publicstatic void main(String[] args){

int SIZE=19;

for(int i=0;i<SIZE;i++){

if(i<10){

System.out.print("  "+i);//两个空格

}else{

System.out.print("  "+(char)(i+'a'-10));//两个空格

}

}

System.out.println();

//      System.out.print(i<10?(char)(i+'0'):(char)(i+'a'-10));

for(int i=0;i<SIZE;i++){

if(i<10){

System.out.print(i+" ");//一个空格

}else{

System.out.print((char)(i+'a'-10)+"");//一个空格

}

for(int j=0;j<SIZE;j++){

System.out.print("*"+"  ");//两个空格

}

System.out.println();

}

}

}

10数组输出唐诗

package day04;

public class ArrayTest {

public static void main(String[] args){

char[][] arr=new char[4][7];

String s="朝辞白帝彩云间千里江陵一日还两岸猿声啼不住轻舟已过万重山";

for(int i=0;i<arr.length;i++){

for(intj=0;j<arr[i].length;j++){

arr[i][j]=s.charAt(i*7+j);

}

}

for(inti=0;i<arr[0].length;i++){

for(intj=0;j<arr.length;j++){

System.out.print(arr[arr.length-j-1][i]+"  ");

}

System.out.println();

}

}

}

11找出满足条件的最小数

package day02;

public class Fangk{

publicstatic void main(String[] args){

//            for(inti=1000;i<=9999;i++){

//                   intq=i/1000;

//                   intb=i/100%10;

//                   ints=i/10%10;

//                   intg=i%10;

//                   if(q>b&& s>g && q+g==b+s && b%2!=0){

//                          System.out.println("TheMin Number is:"+i);

//                          break;

//                   }

//            }

loop1:     for(int q=1;q<=9;q++){

loop2:            for(int b=0;b<=9;b++){

if(b%2==0){

continue loop2;

}

for(ints=0;s<=9;s++){

for(intg=0;g<=9;g++){

if(q>b&& s>g && q+g==b+s){

System.out.println("TheMin Number is:"+(q*1000+b*100+s*10+g));

breakloop1;

}

}

}

}

}

}

}

12判断一个数是否是素数

package day02;

public class Fangk{

publicstatic void main(String[] args){

intnum=14;

booleanflag=true;

for(inti=2;i<=num/2;i++){

if(num%i==0){

flag=false;

break;

}

}

if(flag){

System.out.println(num+"is a prime number!");

}else{

System.out.println(num+"is not a prime number!");

}

}

}

//

package day04;

import java.util.Scanner;

public class A1{

public static void main(String[] args){

int n;

Scanner sca=new Scanner(System.in);

System.out.println("please input anumber:");

n=sca.nextInt();

if(isPrimeNumber(n)){

System.out.println(n+"is aprime number!");

}else{

System.out.println(n+"is nota prime number!");

}

}

public static boolean isPrimeNumber(int n){

for(int i=2;i<=n/2;i++){

if(n%i==0){

return false;

}

}

returntrue;

}

}

13一个数倒序排列

package day02;

public class Daoxu{

publicstatic void main(String[] args){

intolddata=3758;

intnewdata=0;

while(olddata!=0){

for(inti=0;i<4;i++){

newdata=newdata*10+olddata%10;

olddata=olddata/10;

}

System.out.println("newdata="+newdata);

}

}

}

14将一个整数以二进制输出

package day04;

import java.util.Scanner;

public class ArrayTest {

public static void main(String[] args){

int n;

Scanner s=new Scanner(System.in);

System.out.println("please input anumber:");

n=s.nextInt();

for(int i=31;i>=0;i--){

if((n&(1<<i))!=0){

System.out.print("1");

}else{

System.out.print("0");

}

if((32-i)%8==0){

System.out.print("");

}

}

}

}

15矩形图案

package day02;

public class Fangk {

publicstatic void main(String[] args){

intm=5,n=6;

for(inti=0;i<n;i++){

System.out.print("*");

}

System.out.println();

for(int i=0;i<m-2;i++){

System.out.print("*");

for(intj=0;j<n-2;j++){

System.out.print("  ");

}

System.out.print("*");

System.out.println();

}

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

System.out.print("*");

}

}

}

16猜数字

package day02;

import java.util.Scanner;

public class Csz {

publicstatic void main(String[] args) {

Scanners = new Scanner(System.in);

intnum = (int) (Math.random() * 1000);

intm=0;

for(inti=9;i>=0;i--){

System.out.println("pleaseinput your number! ");

m=s.nextInt();

if(m>num){

System.out.println("Toolarge!");

}elseif(m<num){

System.out.println("Toosmall!");

}else{

System.out.println("Youare right!");

break;

}

if(i>0){

System.out.println("还有"+i+"次机会!");

}

}

if(m!=num){

System.out.println("下次再来吧!");

}

}

}

17.HotelManager

package hotel;

import java.util.Scanner;

public class HotelManager {

privatestatic String[][] rooms;// 表示房间

publicstatic void main(String[] args) {

rooms= new String[10][12];

Stringcomm;// 表示用户输入的命令

for(int i = 0; i < rooms.length; i++) {

for(int j = 0; j < rooms[0].length; j++) {

rooms[i][j]= "EMPTY";

}

}

//

while(true) {

System.out.println("请输入命令:");

Scannersca = new Scanner(System.in);

System.gc();

comm= sca.next();

if("search".equalsIgnoreCase(comm)) {

search();

}else if ("in".equalsIgnoreCase(comm)) {

introomNo = sca.nextInt();

Stringname = sca.next();

in(roomNo,name);

}else if ("out".equalsIgnoreCase(comm)) {

introomNo = sca.nextInt();

out(roomNo);

}else if ("exit".equalsIgnoreCase(comm)) {

System.out.println("程序退出...");

break;

}else {

System.out.println("命令输入错误,请重新输入:");

}

}

}

privatestatic void out(int roomNo) {

if("EMPTY".equals(rooms[(roomNo/100)-1][(roomNo%100)-1])){

System.out.println("该房间没有客人入住,退房失败!");

return;

}

rooms[(roomNo/100)-1][(roomNo%100)-1]="EMPTY";

System.out.println(roomNo+"退房成功!");

}

privatestatic void in(int roomNo, String name) {

if(!"EMPTY".equals(rooms[(roomNo/100)-1][(roomNo%100)-1])){

System.out.println("该房间已经有客人入住!");

return;

}

rooms[(roomNo/100)-1][(roomNo%100)-1]=name;

System.out.println(name+"成功入住"+roomNo+"房间!");

}

privatestatic void search() {

for(int i = 0; i < rooms.length; i++) {

//打印房间号

for(int j = 0; j < rooms[0].length; j++) {

if(j + 1 < 10) {

System.out.print(i+ 1 + "0" + (j + 1) + "    ");

}else {

System.out.print(i+ 1 + "" + (j + 1) + "      ");

}

}

//打印房间状态

System.out.println();

for(int j = 0; j < rooms[0].length; j++) {

System.out.print(rooms[i][j]+ "   ");

}

System.out.println();

}

}

}

18.StudentManager

package day05.student_manager;

import java.util.Scanner;

public class StudentManager {

staticint[][] scores=new int[6][5];

staticString[]students={"zhangsan","lisi","wangwu","zhaoliu","qianqi","liuba"};

staticString[]courses={"corejava","jdbc","servlet","jsp","ejb"};

publicstatic void main(String[] args) {

for(inti=0;i<scores.length;i++){

for(intj=0;j<scores[i].length;j++){

scores[i][j]=(int)(Math.random()*100);

}

}

Scanners=new Scanner(System.in);

Stringcomm;

while(true){

System.out.println("请输入命令:");

comm=s.next();

if(comm.equals("AVG")){

Stringpara=s.next();

avg(para);

}elseif(comm.equals("SORT")){

Stringcourse=s.next();

sort(course);

}elseif(comm.equals("GET")){

Stringstudent=s.next();

Stringcourse=s.next();

get(student,course);

}elseif(comm.equals("EXIT")){

break;

}else{

System.out.println("命令格式不正确,请重新输入!");

}

}

}//main()end!

publicstatic void avg(String para){

intsIndex=-1;

intcIndex=-1;

for(inti=0;i<students.length;i++){

if(students[i].equals(para)){

sIndex=i;

}

}

if(sIndex==-1){

for(inti=0;i<courses.length;i++){

if(courses[i].equals(para)){

cIndex=i;

}

}

}

if(sIndex==-1&& cIndex==-1){

System.out.println("找不到学生或课程!");

return;

}

doubleavg=0.0;

if(sIndex!=-1){

for(inti=0;i<scores[sIndex].length;i++){

avg+=scores[sIndex][i];

}

avg/=scores[sIndex].length;

System.out.println("学生:"+para+"的平均分是:"+avg);

}else{

for(inti=0;i<scores.length;i++){

avg+=scores[i][cIndex];

}

avg/=scores.length;

System.out.println("课程:"+para+"的平均分是:"+avg);

}

}

publicstatic void sort(String course){

int[]courseScore=new int[scores.length];

if(course.equals("sum")){//如果求总分的排名

//                   //求出每个学生的总分,将成绩存放在courseScore数组中

for(inti=0;i<scores.length;i++){

intstudentSum=0;

for(intj=0;j<scores[i].length;j++){

studentSum+=scores[i][j];

}

courseScore[i]=studentSum;

}

}else{//如果不是求总分排名

intcIndex=-1;

for(inti=0;i<courses.length;i++){//找到这门课程的下标

if(courses[i].equals(course)){

cIndex=i;

}

}

if(cIndex!=-1){//如果是一门有效的课程

//把scores数组中这一列的值放到courseScore数组中!

for(inti=0;i<scores.length;i++){

courseScore[i]=scores[i][cIndex];

}

}else{//如果不是一门有效的课程

System.out.println("课程名不正确,请重新输入!");

return;

}

}

String[]studentCopy=new String[students.length];

System.arraycopy(students,0, studentCopy, 0, students.length);

for(inti=0;i<courseScore.length-1;i++){

for(intj=i+1;j<courseScore.length;j++){

if(courseScore[i]<courseScore[j]){

inttemp=courseScore[i];

courseScore[i]=courseScore[j];

courseScore[j]=temp;

Stringstemp=studentCopy[i];

studentCopy[i]=studentCopy[j];

studentCopy[j]=stemp;

}

}

}

intorder=1;

System.out.println("名次\t学生\t成绩");

for(inti=0;i<courseScore.length;i++){

if(i!=0&& courseScore[i]==courseScore[i-1]){

order--;

}else{

order=i+1;

}

System.out.print(order+"\t");

System.out.print(studentCopy[i]+"\t");

System.out.println(courseScore[i]);

order++;

}

}

publicstatic void get(String student,String course){

intsIndex=-1;

intcIndex=-1;

for(inti=0;i<students.length;i++){

if(students[i].equals(student)){

sIndex=i;

}

}

if(sIndex==-1){

System.out.println("没有这个学生:"+student);

return;

}

if(course.equals("sum")){//如果求总分

intstudentSum=0;

for(intj=0;j<scores[sIndex].length;j++){

studentSum+=scores[sIndex][j];

}

System.out.println(student+"学生的总分为:"+studentSum);

return;

}

for(inti=0;i<courses.length;i++){

if(courses[i].equals(course)){

cIndex=i;

}

}

if(cIndex==-1){

System.out.println("没有这门课程:"+course);

return;

}

System.out.println(student+"学生的"+course+"课程的成绩为:"+scores[sIndex][cIndex]);

}

}

19.Five

package hotel;

import java.util.Scanner;

/**

* 首先在程序第一次运行的时候,构建出棋盘,切以后

* 不能再从新构建,知道结束,所以将其放到静态代码块中。

*@author zhz

*

*/

public class Five {

//由于矩阵要保存输入的信息,所以要设置成全局变量,整个程序就一个

privatestatic String[][] five=new String[17][17];

static{

//构建并打印棋盘

drawFive();

}

publicstatic void main(String[] args) {

//请白棋下子

while(true){

System.out.println("请白棋下子");

Pointp1=pleaseIn();

if(!five[Integer.parseInt(p1.getX())][Integer.parseInt(p1.getY())].equals("*")){

System.out.println("无效的位置,视为自动放弃");

}

runPoint(p1,"white");

gameover(p1);

System.out.println("请黑棋下子");

Pointp2=pleaseIn();

if(!five[Integer.parseInt(p2.getX())][Integer.parseInt(p2.getY())].equals("*")){

System.out.println("无效的位置,视为自动放弃");

}

runPoint(p2,"black");

gameover(p2);

}

}

//根据用户的输入信息,对棋盘的坐标进行赋值,白棋@ 黑棋O,并且将当前棋盘的信息输出

privatestatic void runPoint(Point p,String str){

//根据px py来获取行和列的坐标

intx=Integer.parseInt(p.getX()),y=Integer.parseInt(p.getY());

if(str.equals("white")){

five[x][y]="@";

}else{

five[x][y]="O";

}

outFive();

}

//用户输入要放棋子的坐标    并且自动转换为具体的坐标

privatestatic Point pleaseIn(){

Scannersc=new Scanner(System.in);

Pointp=new Point(sc.next(),sc.next());

Stringpx=p.getX();

Stringpy=p.getY();

//根据px py来获取行和列的坐标

intx=0,y=0;

for(inti=1;i<five.length;i++){

if(five[i][0].equals(px)){

x=i;

}

if(five[0][i].equals(py)){

y=i;

}

}

returnnew Point(x+"",y+"");

}

/**判断胜负,根据当前点,开始计算,如果有五个点连成线,则盛,程序提示结束,并显示输赢

*

* @param p

*/

publicstatic void gameover(Point p) {

intx=Integer.parseInt(p.getX()),y=Integer.parseInt(p.getY());

intc1 = 0, c2 = 0, c3 = 0, c4 = 0;

booleanl1 = true, l2 = true, l3 = true, l4 = true, l5 = true, l6 = true, l7 = true, l8= true;

for(int i = 1; i <5 ; i++) {

//竖直向上

if(y - i >= 1

&&five[x][y - i].equals(five[x][y])

&&l1) {

c1++;

}else {

l1= false;

}

//竖直向下

if(y + i <= 16

&&five[x][y + i].equals(five[x][y])

&&l2) {

c1++;

}else {

l2= false;

}

//水平向左

if(x - i >= 1

&&five[x - i][y].equals(five[x][y])

&&l3) {

c2++;

}else {

l3= false;

}

//水平向右

if(x + i <= 16

&&five[x + i][y].equals(five[x][y])

&&l4) {

c2++;

}else {

l4= false;

}

//斜向左上

if(x - i >= 1 && y - i >= 1

&&five[x - i][y - i].equals(five[x][y])

&&l5) {

c3++;

}else {

l5= false;

}

//斜向右下

if(x + i <= 16 && y + i <= 16

&&five[x + i][y + i].equals(five[x][y])

&&l6) {

c3++;

}else {

l6= false;

}

//斜向左下

if(x - i >= 1 && y + i <= 16

&&five[x - i][y + i].equals(five[x][y])

&&l7) {

c4++;

}else {

l7= false;

}

//斜向右上

if(x + i <= 16 && y - i >= 1

&&five[x + i][y - i].equals(five[x][y])

&&l8) {

c4++;

}else {

l8 = false;

}

}

if(c1 >= 4 || c2 >= 4 || c3 >= 4 || c4 >= 4) {

if(five[x][y].equals("1")) {

System.out.println("黑棋获胜!");

System.exit(0);

}else {

System.out.println("白棋获胜!");

System.exit(0);

}

}

}

//构造棋盘

privatestatic void drawFive(){

//构建棋盘边框

String[]sr=new String[]{"","0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};

five[0]=sr;

for(inti=0;i<five.length;i++){

five[i][0]=sr[i];

}

//构建棋盘内容

for(inti=1;i<five.length;i++){

for(intj=1;j<five[0].length;j++){

five[i][j]="*";

}

}

//打印棋盘

outFive();

}

//打印棋盘

privatestatic void outFive(){

for(inti=0;i<five.length;i++){

for(intj=0;j<five[0].length;j++){

System.out.print(five[i][j]+"");

}

System.out.println();

}

}

}

20.CardGame

package day05.cardGame;

import java.util.Scanner;

public class CardGame {

staticint[] twoHandsCards=new int[6];

staticint userAMoney=0;

staticint userBMoney=0;

publicstatic void main(String[] args) {

Scanners=new Scanner(System.in);

System.out.println("请输入总赌本:");

userAMoney=s.nextInt();

userBMoney=userAMoney;

intcurrentMoney=0;

while(userAMoney>0&& userBMoney>0){

System.out.println("请输入本局赌注:");

currentMoney=s.nextInt();

if(currentMoney<=0|| currentMoney>userAMoney || currentMoney>userBMoney){

System.out.println("赌注不正确,请重新输入!");

continue;

}

dispatchCards();

printCards(twoHandsCards);

if(compare()>0){

userAMoney+=currentMoney;

userBMoney-=currentMoney;

System.out.println("玩家获胜!");

}elseif(compare()<0){

userAMoney-=currentMoney;

userBMoney+=currentMoney;

System.out.println("电脑获胜!");

}else{

System.out.println("平局!");

}

System.out.println("玩家赌本:"+userAMoney+";电脑赌本:"+userBMoney);

}

}

publicstatic void dispatchCards(){

inti=0;

while(i<twoHandsCards.length){

inth=(int)(Math.random()*4)+1;

intd=(int)(Math.random()*13)+2;

intj=0;

for(;j<i;j++){

if(twoHandsCards[j]==h*100+d){

break;

}

}

if(j<i){

continue;

}else{

twoHandsCards[i++]=h*100+d;

}

}

}

publicstatic void printCards(int[] oneHandCards){

for(inti=0;i<oneHandCards.length;i++){

switch(oneHandCards[i]/100){

case1:System.out.print("黑");break;

case2:System.out.print("红");break;

case3:System.out.print("梅");break;

case4:System.out.print("方");break;

}

if(oneHandCards[i]%100<=10){

System.out.print(oneHandCards[i]%100);

}else{

switch(oneHandCards[i]%100){

case 11: System.out.print("J");break;

case 12:System.out.print("Q");break;

case 13:System.out.print("K");break;

case 14:System.out.print("A");break;

}

}

System.out.print("  ");

}

System.out.println();

}

publicstatic  int compare(){

int[]aCards=new int[3];

int[]bCards=new int[3];

for(inti=0;i<3;i++){

aCards[i]=twoHandsCards[i];

}

for(inti=3;i<6;i++){

bCards[i-3]=twoHandsCards[i];

}

returnfromCardsToNumber(aCards)-fromCardsToNumber(bCards);

}

publicstatic int fromCardsToNumber(int[] oneHandCards){

for(inti=0;i<oneHandCards.length-1;i++){

for(intj=i+1;j<oneHandCards.length;j++){

if(oneHandCards[i]%100<oneHandCards[j]%100){

inttemp=oneHandCards[i];

oneHandCards[i]=oneHandCards[j];

oneHandCards[j]=temp;

}

}

}

intnum=0;

if(oneHandCards[0]%100==oneHandCards[1]%100&& oneHandCards[1]%100==oneHandCards[2]%100){

num=6*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}elseif(oneHandCards[0]/100==oneHandCards[1]/100 &&

oneHandCards[1]/100==oneHandCards[2]/100&&

oneHandCards[0]%100==oneHandCards[1]%100+1&&

oneHandCards[1]%100==oneHandCards[2]%100+1

){

num=5*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}elseif(oneHandCards[0]/100==oneHandCards[1]/100 &&

oneHandCards[1]/100==oneHandCards[2]/100){

num=4*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}elseif(oneHandCards[0]%100==oneHandCards[1]%100+1 &&

oneHandCards[1]%100==oneHandCards[2]%100+1){

num=3*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}elseif(oneHandCards[0]%100==oneHandCards[1]%100 ){

num=2*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}elseif(oneHandCards[1]%100==oneHandCards[2]%100){

num=2*1000000+oneHandCards[1]%100*10000+oneHandCards[2]%100*100+oneHandCards[0]%100;

}else{

num=1*1000000+oneHandCards[0]%100*10000+oneHandCards[1]%100*100+oneHandCards[2]%100;

}

returnnum;

}

}

二十个JAVA程序代码相关推荐

  1. Java面试题16 牛客 以下java程序代码,执行后的结果是()

    Java面试题16 牛客 以下java程序代码,执行后的结果是() 1 2 3 4 5 6 7 8 9 10 public class Test {     public static void ma ...

  2. 《Java和Android开发实战详解》——2.5节良好的Java程序代码编写风格

    本节书摘来自异步社区<Java和Android开发实战详解>一书中的第2章,第2.5节良好的Java程序代码编写风格,作者 陈会安,更多章节内容可以访问云栖社区"异步社区&quo ...

  3. 编写一个程序实现方法的覆盖java_编写Java程序代码必须先声明一个____,然后在其中编写实现需求的业务代码。...

    [多选题]下列关于多行注释的应用,正确的是( ) [单选题]是在思维中把对象分解为各个部分.侧面.属性以及阶段,分别加以考察的方法.(1.0分) [判断题]多行注释"/*...*/" ...

  4. 简单的java程序代码?

    我需要一段最简单的java代码程序 1.最简单的java代码肯定就是这个了,如下:public class MyFirstApp { public static void main(String[] ...

  5. 最近开始研究PMD(一款采用BSD协议发布的Java程序代码检查工具)

    PMD是一款采用BSD协议发布的Java程序代码检查工具.该工具可以做到检查Java代码中是否含有未使用的变量.是否含有空的抓取块.是否含有不必要的对象等.该软件功能强大,扫描效率高,是Java程序员 ...

  6. java 答题卡_试题八(共15分)阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]在 - 赏学吧...

    试题八(共15分) 阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内. [说明] 在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类H ...

  7. java 代码阅读题_● 试题三 阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 1.S - 赏学吧...

    ● 试题三 阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内. [说明] 1.SMTP是发送E-mail的协议,常用以下5条命令发送E-mail: ·HELO,与SMTP服务 ...

  8. 安卓版的java程序代码

    正确例题 import java.util.*; public class Ha{ public static void main(String[] args) { String a[]={" ...

  9. java程序代码的运行机制_1.4Java程序的运行机制

    Java 程序的运行必须经过编写.编译和运行 3 个步骤. 编写:是指在 Java 开发环境中进行程序代码的输入,最终形成后缀名为 .java 的 Java 源文件. 编译:是指使用 Java 编译器 ...

  10. Android studio如何运行java程序代码

    先看Java程序类 public class GGG {public static void main(String[] args) {System.out.println("我是java程 ...

最新文章

  1. java 内存详解_Java内存详解
  2. 谁来谈谈Google Earth的核心技术和架构?(转)
  3. 基于正样本的表面缺陷检测
  4. Ehab and another construction problem(水题)
  5. 粤西茂名实现光网全覆盖 智慧城市改变民众生活
  6. java开发cms视频教程下载地址_Java + MySQL 开发CMS系统实例教程
  7. html转邮件html格式转换,如何把电子邮件格式改成HTML格式
  8. 一个封锁操作被对wsacancelblockingcall_突破封锁再进一步,华为鸿蒙OS成功登上手机...
  9. 西安周边旅游++军事纪实
  10. 【数据结构】【cfs_rq】【task_struct】【sched_domain】
  11. xml保存图片和读取图片
  12. React文件预览,React实现在线预览docx,xslx,pdf格式文件
  13. 后端开发工程师的生命周期,生命在于学习
  14. 自定义8583模板,打包解包,使用j8583包
  15. influxdb删除column
  16. Linux安装mql
  17. 为什么要用python处理excel-以Excel处理为目的学习python还是VBA?
  18. WPS计算机一级考试知识点,计算机一级考试WPS练习题及答案
  19. 思岚科技—SLAMTEC将自家研发技术应用到更多行业中
  20. 【3dsmax新手入门】-实体立方八面晶体绘制

热门文章

  1. 为什么grab显示无法定位_西门子SIPARTPS2阀门定位器的故障处理
  2. 部署到gcp_Linux基础架构学习 - 使用GCP托管云解决方案 - Day09
  3. 2 多贝西小波_【原创】土超:安卡拉高古VS贝西克塔斯
  4. string.join用法
  5. 【BZOJ1057】[ZJOI2007] 棋盘制作(单调栈的运用)
  6. TensorFlow 学习可视化 TensorBoard 简易教程
  7. 代码设定的按钮与storyboard中的xib页面间的跳转
  8. jad的用法(反编译某目录下所有class)
  9. win7下u盘安装ubuntu组成双系统
  10. 评国内三大B2C网站首页的信息架构