JiveJdon Community Forums
在线173人 J道首页 | 论坛首页 | 培训咨询 | 开源框架 | 精华 | 查搜 | 注册 | 登陆 |
首页 » 论坛 » J2EE/JavaEE/JEE/EJB/JSF等技术讨论
???en_US.forumThreadPrev.name??? 上一主题
Go back to the topic listing   返回主题列表
???en_US.forumThreadNext.name??? 下一主题
这个主题共有 9 回复 / 1 页 [ ]  发表新帖子  回复该主题贴
anckypaine

发表文章: 1
注册时间: 2007年10月23日 11:56
高手帮忙解决两道JAVA题,跪谢!! 发表: 2007年10月23日 11:57 回复
小弟不才,高手帮忙解决两道题,十分感谢!!!
(1)输入两个字符串做比较,如果长度相等并且出现的字母相同,则认为两个字符串相等,例如:abc 和 bca

(2)求序列 2/1 , 3/2 , 5/3 , 8/5 , 13/8 , 21/13 .....前20个序列的和
cosina

发表文章: 15
注册时间: 2007年06月08日 14:00
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 全局变量可能 不好:)
profly

发表文章: 2
注册时间: 2007年10月26日 18:16
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];
}
}
}
profly

发表文章: 2
注册时间: 2007年10月26日 18:16
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有段时间 代码没怎么写多少,练练。。。。:)
fudong

发表文章: 6
注册时间: 2007年10月18日 18:56
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;
}
fudong

发表文章: 6
注册时间: 2007年10月18日 18:56
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());
}

}
xunfengkuohai

发表文章: 2
注册时间: 2007年11月06日 22:38
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);
}
}
xunfengkuohai

发表文章: 2
注册时间: 2007年11月06日 22:38
re:高手帮忙解决两道JAVA题,跪谢!! 发表: 2007年11月06日 22:42 回复
想问一下,第一个问题是字母个数一样就行了吗
wyf521125

发表文章: 1
注册时间: 2007年11月08日 20:05
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;
}
ljxksy566

发表文章: 1
注册时间: 2007年12月02日 11:52
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
这个主题有 9 回复 / 1 页 [ ]
???en_US.forumThreadPrev.name??? 上一主题
Go back to the topic listing   返回主题列表    返回页首  返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Spring Struts
查询本论坛内 回复超过的热门帖子
快速发表回复
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
 

解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-07 jdon.com

anti spam