Topic: JAVA 魂牵梦绕的一道难题 |
Print this page |
1.JAVA 魂牵梦绕的一道难题 | Copy to clipboard |
Posted by: jasonhero Posted on: 2006-05-17 13:09 有人做了一件好事,A说不A做的,B说是C做的,C说是D做的,D说C在说谎,三人说真话,一人说假话,编程得出好事是谁做的? 算法: A说不是A做的:0A 1BCD B说是C做的: 1C 1C C说是D做的: 1D 1D D说C在说谎: 0D 1ABC 然后把它们存到一个二维数组中,查找出现三次的那个字符就是做好事的人 代码如下: import java.io.*; public class t { static String str1[]={"A","B","C","D"}; static String str2[][]={{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"}}; static int k=0; public static void main(String args[])throws IOException { int bA; String b1,b2,b3,b4,c1,c2,c3,c4; //输入A BufferedReader aIn=new BufferedReader(new InputStreamReader(System.in)); System.out.println("A说:"); b=aIn.readLine(); bA=Integer.parseInt; c=aIn.readLine(); char g = c.charAt(0); hanshu(bA,g);//函数调用 System.out.println("B说:"); b2=aIn.readLine(); bA=Integer.parseInt(b2); c2=aIn.readLine(); char g2 = c2.charAt(0); hanshu(bA,g2);//函数调用 System.out.println("C说:"); b3=aIn.readLine(); bA=Integer.parseInt(b3); c3=aIn.readLine(); char g3 = c3.charAt(0); hanshu(bA,g3);//函数调用 System.out.println("D说:"); b4=aIn.readLine(); bA=Integer.parseInt(b4); c4=aIn.readLine(); char g4 = c4.charAt(0); hanshu(bA,g4);//函数调用 //bA和c的输出 System.out.println(bA); System.out.println; //数组输出 for(int i=0;i<4;i++) System.out.print(str1+" "); System.out.println("\n"); for(int i=0;i<4;i++) { System.out.println("\n"); for(int j=0;j<4;j++) System.out.print(str2[j]+" "); } } //函数 static void hanshu(int x,char y) { String comp = ""; comp += y; switch { case 0: for(int i=0;i<4;i++) { if(comp==str1) str1="*"; if(comp!=str1) str2[0][k]=str1; k++; } break; } } } 此代码出现几个错误,但在下苦思冥想的确是无能为力了,真诚求教高手解答,先谢过 |
2.Re:JAVA 魂牵梦绕的一道难题 [Re: jasonhero] | Copy to clipboard |
Posted by: java学生 Posted on: 2006-05-17 21:21 恩,看不懂! |
3.Re:JAVA 魂牵梦绕的一道难题 [Re: jasonhero] | Copy to clipboard |
Posted by: king431 Posted on: 2006-05-19 21:43 很难明白!虽然不能帮到你,但是帮你顶一下 |
4.Re:JAVA 魂牵梦绕的一道难题 [Re: jasonhero] | Copy to clipboard |
Posted by: oujianqiang Posted on: 2006-05-21 10:05 已修改,看是不是你想要的结果 import java.io.*; public class t { static String str1[]={"A","B","C","D"}; static String str2[][]={{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"}}; public static void main(String args[])throws IOException { int bA; String b1,b2,b3,b4,c1,c2,c3,c4; //输入A BufferedReader aIn=new BufferedReader(new InputStreamReader(System.in)); System.out.println("A说:"); b1=aIn.readLine(); bA=Integer.parseInt(b1); c1=aIn.readLine(); String g = c1.substring(0,0); hanshu(bA,g);//函数调用 System.out.println("B说:"); b2=aIn.readLine(); bA=Integer.parseInt(b2); c2=aIn.readLine(); String g2 = c2.substring(0,0); hanshu(bA,g2);//函数调用 System.out.println("C说:"); b3=aIn.readLine(); bA=Integer.parseInt(b3); c3=aIn.readLine(); String g3 = c3.substring(0,0); hanshu(bA,g3);//函数调用 System.out.println("D说:"); b4=aIn.readLine(); bA=Integer.parseInt(b4); c4=aIn.readLine(); String g4 = c4.substring(0,0); hanshu(bA,g4);//函数调用 //bA和c的输出 System.out.println(bA); System.out.println(); //数组输出 for(int i=0;i<4;i++) System.out.print(str1[i]+" "); System.out.println("\n"); for(int i=0;i<4;i++) { System.out.println("\n"); for(int j=0;j<4;j++) System.out.print(str2[i][j]+" "); } } //函数 static void hanshu(int x,String y) { String comp; comp=y; int k=0; switch { case 0: for(int i=0;i<4;i++) { if(comp.equals(str1[i])) str1[i]="*"; else { str2[0][k]=str1[i]; k++; } } break; } } } |
5.Re:JAVA 魂牵梦绕的一道难题 [Re: jasonhero] | Copy to clipboard |
Posted by: haiboxiaozi Posted on: 2006-05-21 15:16 好象有点难?看不懂,顶一下吧1 |
6.Re:JAVA 魂牵梦绕的一道难题 [Re: jasonhero] | Copy to clipboard |
Posted by: qingzhipan027 Posted on: 2006-05-22 11:49 我改了下,语法上没什么问题了,可是好像执行不了…… import java.io.*; public class t { static String str1[]={"A","B","C","D"}; static String str2[][]={{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"},{"*","*","*","*"}}; public static void main(String args[])throws IOException { int bA; String b1,b2,b3,b4,c1,c2,c3,c4; BufferedReader aIn=new BufferedReader(new InputStreamReader(System.in)); //输入A System.out.println("A说:"); b1=aIn.readLine(); bA=Integer.parseInt(b1); c1=aIn.readLine(); String g = c1.substring(0,0); hanshu(bA,g);//函数调用 System.out.println("B说:"); b2=aIn.readLine(); bA=Integer.parseInt(b2); c2=aIn.readLine(); String g2 = c2.substring(0,0); hanshu(bA,g2);//函数调用 System.out.println("C说:"); b3=aIn.readLine(); bA=Integer.parseInt(b3); c3=aIn.readLine(); String g3 = c3.substring(0,0); hanshu(bA,g3);//函数调用 System.out.println("D说:"); b4=aIn.readLine(); bA=Integer.parseInt(b4); c4=aIn.readLine(); String g4 = c4.substring(0,0); hanshu(bA,g4);//函数调用 //bA和c的输出 System.out.println(bA); System.out.println(); //数组输出 for(int i=0;i<4;i++) System.out.print(str1[i]+" "); System.out.println("\n"); for(int i=0;i<4;i++) { System.out.println("\n"); for(int j=0;j<4;j++) System.out.print(str2[i][j]+" "); } } //函数 static void hanshu(int x,String y) { String comp; comp=y; int k=0; switch(x) { case 0: for(int i=0;i<4;i++) { if(comp.equals(str1[i])) str2[k][i]="*"; else str2[k][i]=str1[i]; } k++; break; case 1: for(int i=0;i<4;i++) { if(comp.equals(str1[i])) str2[k][i]=str1[i]; else str2[k][i]="*"; } k++; break; } } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |