|
这个主题共有 9 回复 / 1 页 [
]
|
|
|
|
|
|
高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年10月23日 11:57
|
回复
|
|
小弟不才,高手帮忙解决两道题,十分感谢!!! (1)输入两个字符串做比较,如果长度相等并且出现的字母相同,则认为两个字符串相等,例如:abc 和 bca
(2)求序列 2/1 , 3/2 , 5/3 , 8/5 , 13/8 , 21/13 .....前20个序列的和
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年10月24日 10:29
|
回复
|
|
private void getValue(int a,int b,int count){ if(count -- > 0) total += b/a; int c = b; b = a + b; a = c; getValue(a,b,count); }
要个total 全局变量可能 不好:)
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年10月26日 18:17
|
回复
|
|
public class Test { static int[] arr ; static double ret; public static void main(String[] agrs) { double temp; getXulie(21); for(int i=0;i<arr.length-1;i++) { temp = (double)arr[i+1]/arr; //System.out.println(temp); ret += temp; } System.out.println(ret); } public static void getXulie(int num) { arr = new int[num]; arr[0] = 1; arr[1] = 2; for(int i=2;i<num;i++) { arr = arr[i-1] + arr[i-2]; } } }
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年10月30日 15:57
|
回复
|
|
public boolean isEques(String str1,String str2) { int len1 = str1.length(); int len2 = str2.length(); int c1 = 0,c2 = 0; char ch;
if(len1 != len2) return false; else { for(int n=0;n<len1;n++) { ch = str1.charAt(n); for(int i=0;i<len1;i++) { if(ch == str1.charAt(i)) c1++; if(ch == str2.charAt(i)) c2++; } if(c1 == c2) { c1 = 0; c2 = 0; continue; } else { return false; } } return true; } } //学JAVA有段时间 代码没怎么写多少,练练。。。。:)
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年11月06日 15:05
|
回复
|
|
public boolean Isequel(String str1,String str2) { if(str1.length()!=str2.length()) { return false; } else { char[] ch1=str1.toCharArray(); char[] ch2=str2.toCharArray(); java.util.Arrays.sort(ch1); java.util.Arrays.sort(ch2); if(java.util.Arrays.equals(ch1, ch2)) return true; } return false; }
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年11月06日 15:33
|
回复
|
|
package esaytest;
public class totalcount { public float count() { int a=1; int b=2; int c; float f2=0; for(int i=0;i<20;i++) { float f1=(float)b/(float)a; f2=f2+f1; c=b; b=a+b; a=c; } return f2; } public static void main(String[] args) { totalcount tc=new totalcount(); System.out.println(tc.count()); }
}
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年11月06日 22:38
|
回复
|
|
2: import javax.swing.JOptionPane; public class add { public static void main(String args[]) { int n; String number = JOptionPane.showInputDialog(null,"enter a number","number",JOptionPane.QUESTION_MESSAGE); n = Integer.parseInt(number); float result=0; float k,u; k=1; u=2; for(int i=0;i<n;i++) { result = result + u/k; u=u+k; k=u-k; System.out.println(u+" "+k); } JOptionPane.showMessageDialog(null,"Result is " + result,"result",JOptionPane.INFORMATION_MESSAGE); } }
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年11月06日 22:42
|
回复
|
|
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年11月08日 20:07
|
回复
|
|
(1)输入两个字符串做比较,如果长度相等并且出现的字母相同,则认为两个字符串相等,例如:abc 和 bca boolean CompareTwoStringValue(String a,String b) { boolean f = false; if(a==null||b==null) return f; if(a.length()!=b.length()) return f; else if(a.hashCode()==b.hashCode()) f=true; else { int a_h = 0 ; int b_h = 0 ; String [] a_s = a.split("|") ; String [] b_s = b.split("|") ; for(int i=0;i<a.length()+1;i++) { a_h += a_s.hashCode(); b_h += b_s.hashCode(); } if(a_h==b_h) f=true; } return f; }
|
|
|
|
|
|
re:高手帮忙解决两道JAVA题,跪谢!!
|
发表: 2007年12月02日 15:47
|
回复
|
|
(1)输入两个字符串做比较,如果长度相等并且出现的字母相同,则认为两个字符串相等,例如:abc 和 bca import javax.swing.*; import java.util.*; public class Compare{ pubilc static void main(String[] args){ String str1,str2; str1=JOptionPane.showInputDialog(null,"enter a String","str1",JOptionPane.QUESTION_MESSAGE); str2=JOptionPane.showInputDialog(null,"enter a String","str2",JOptionPane.QUESTION_MESSAGE); int str1Length=str1.length(); int str2Length=str2.length(); if (str1Length!=str2Length) return fase; JOptionPane.showMessageDialog(null,"Result is " + "false","result",JOptionPane.INFORMATION_MESSAGE); else { char array1[]=str1.toCharArray(); chat array2[]=str2.toCharArray(); Arrays.sort(array1); Arrays.sort(array2); if(Arrays.equals(array1, array2)) return true; JOptionPane.showMessageDialog(null,"Result is " +"true","result",JOptionPane.INFORMATION_MESSAGE); else return false; JOptionPane.showMessageDialog(null,"Result is " + "false","result",JOptionPane.INFORMATION_MESSAGE); } } // end main method }//end Compare class
|
|
|
|