实训第二天
今天我们的组内成员:陈忠 徐庆祥 石家丞 石磊 赵庭凯 富裕
完成的功能 | 实现了黄金点的游戏,又进行了单词接龙的代码 |
遇到的困难 | 在进行接龙是找出了最长的串,但是没找到头一个元素 |
黄金点完善的代码部分:
1 import java.util.Scanner; 2 import java.lang.*; 3 public class a{ 4 public static double count(double d[],int size) 5 { 6 double sum=0.0; 7 for (int i=0;i<size;i++) 8 sum=sum+d[i]; 9 return sum; 10 } 11 public static void main (String args[]){ 12 System.out.print("游戏人数:"); 13 Scanner cin = new Scanner(System.in); 14 int n=cin.nextInt(); 15 double [] shu=new double[n]; 16 double [] b=new double[n]; 17 double [] c=new double[n]; 18 for (int i=0;i<n;i++) 19 { 20 System.out.print("第"+(i+1)+"个同学输入的数:"); 21 double m=cin.nextDouble(); 22 shu[i]=m; 23 } 24 double sum=a.count(shu,n); 25 double A=sum/n; 26 double h=A*0.618; 27 System.out.println("黄金点:"+h); 28 for (int i=0;i<n;i++) 29 { 30 b[i]=Math.abs(h-shu[i]); 31 double min=b[0]; 32 double max=b[0]; 33 for(int j=0;j<n;j++) 34 { 35 if (b[j]<min) 36 min=b[j]; 37 } 38 for (int k=0;k<n;k++) 39 { 40 if (b[k]==min) 41 c[k]=n; 42 else 43 c[k]=0; 44 } 45 for (int l=0;l<n;l++) 46 { 47 if (b[l]>max) 48 max=b[l]; 49 } 50 for (int o=0;o<n;o++) 51 { 52 if (b[o]==max) 53 c[o]=-2; 54 } 55 } 56 for (int p=0;p<n;p++) 57 { 58 System.out.println("第"+(p+1)+"个同学的成绩:"+c[p]); 59 } 60 } 61 }
单词接龙的代码:
1 import java.io.*; 2 import java.lang.*; 3 4 public class jl { 5 public static void main(String[] args) { 6 int i = 0; 7 String bufToString = ""; 8 String readLine = ""; 9 String n = ""; 10 String[] a = new String[10]; 11 String[] b = new String[9]; 12 try { 13 FileReader fileReader = new FileReader("123.txt"); 14 BufferedReader buf = new BufferedReader(fileReader); 15 while ((readLine = buf.readLine()) != null) { 16 a[i] = readLine; 17 i++; 18 } 19 } catch (Exception e) { 20 e.printStackTrace(); 21 } 22 for (int j = 0; j < b.length; j++) { 23 b[j] = a[j].toLowerCase(); 24 //System.out.println(b[j]); 25 } 26 String y = ""; 27 String z = ""; 28 int c = 0; 29 int max = 0; 30 for (int m = 0; m < b.length; m++) { 31 char w = b[m].charAt(b[m].length() - 1); 32 // System.out.println(w); 33 for (int x = m + 1; x < b.length; x++) { 34 char t = b[x].charAt(0); 35 // System.out.println(t); 36 if (w == t) 37 { 38 39 w = a[x].charAt(a[x].length() - 1); 40 c++; 41 //z=b[m]; 42 //y = y.concat(a[m]); 43 //System.out.println("-----"+m); 44 //System.out.print(w);s 45 if (c>max) 46 { 47 //System.out.print(m); 48 // System.out.print(u); 49 y = y.concat(a[x]); 50 //System.out.println(y); 51 max = c; 52 c = 0; 53 } 54 } 55 } 56 } 57 58 for (int r=0;r<b.length;r++) 59 { 60 char u=b[r].charAt(b[r].length()-1); 61 String y1=y.toLowerCase(); 62 char t=y1.charAt(0); 63 if (t==u) 64 { 65 y=a[r].concat(y); 66 try 67 { 68 BufferedWriter w=new BufferedWriter(new FileWriter("c.txt",true)); 69 w.write(y); 70 w.close(); 71 } 72 catch(Exception e) 73 { 74 System.out.println("error"); 75 } 76 System.out.println(y); 77 } 78 } 79 } 80 }
学习工作和总结:
这是经过完善的代码,感谢各位老师的指点。使我们的问题得到了解决,非常开心。至于从文件中读取数据,还需要研究一下。
今天我们做了单词接龙,在老师和同学的帮助下,我们顺利的完成了任务,虽然过程有点辛苦,但是我们学到了知识,使我们丰富了头脑。
也让我们明白了团队合作的重要性。俗话说“人多力量大”,在今后的的生活中,我们也应该互相帮助
关于JAVA我们也了解到了很多,还有我们很多不知道的知识。有待提高!
会议截图:
运行结果截图: