真晕..555 哪位好心人教导一下 急着用

来源:百度知道 编辑:UC知道 时间:2024/06/17 15:17:47
1 编写applet 程序的页面输出 红色的 "hello would !"

2 找出两个字符串中所有共同的子字符串

3 将碾转相除法求两个整数的最大公因数gcd(a,b)用递归方法实现.
(1) 求两个整数a,b的最小公倍数.
(2) 求撒们个整数a,b,c的最大公约数

4 求满足1+2+...+n<5,6,7,8的最大n值 (application)

5 请编写程序由程序的参数给一个字符串,然后由程序位计算并输出在该字符串出现的次数.

6 int a[]={2,4,1,3,5}要求对其进行非降序排列

以上都是用 java 编写的 请各位不吝赐教

第二题:[经测试没问题,但太麻烦,求简单方法]
//求两个字符串公有的子字符串
public String getPubStr(String str1,String str2) throws Exception
{
String temp="";
int x;
int y;
int count=0;
if(str1.length()>str2.length())//如果str1的长度大于str2的长度

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

for(int j=0;j<str2.length();j++)
{

if(str1.substring(i,i+1).equals(str2.substring(j,j+1)))
{
x=i;y=j;

while(str1.substring(x,x+1).equals(str2.substring(y,y+1)))
{
count++;
temp+=str1.substring(x,x+1);
x++;y++;
if(x>str1.length()-1 || y>str2.length()-1)
{break;}
}
temp=temp+",";
}
}
if(count>0)
{
i=i+count;
count=0;
}else
{
i++;
}
}
}