| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1938 人关注过本帖
标题:几道编程题不会,大家看看要怎么做?
只看楼主 加入收藏
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
 问题点数:0 回复次数:26 
几道编程题不会,大家看看要怎么做?

1。.求解两个输入正整数的最大公约数。
public class GreatestCommonDivisor
{
public int getnum(int a,int b)
{
.....
}
}



2。从命令行读入一个以逗号隔开数字序列,对其排序并按照降序排列输出
public class NumberInputSort{
public String sortNumberInput(String input)
{
,,,,,,
}
}


3。从命令行读入一个字符串和一个文件名,输出文件中字符串存在与否,如果存在那么输出出现的次数
public class FindString
{
public boolean isStringExist(String filePath,String stringToFind)
{
...
}
public int existCount(String filePath,String stringToFind)
{
......
}


4。给定一个字符串,求这个字符串中的从左边开始的第一个最长的子串,这个子串必须在该字符串的逆串中也被包含。
如:"XBCDEFYWFEDCBZ" 中包含"BCDEF"子串,而其逆串”ZBCDEFWYFEDCBX"中同样包含这个子串。
Returns :"BCDEF"
public class ReverseSubstring
{
public string findReversed(String input)
{
.....
}
}

谢谢!!!

[此贴子已经被作者于2006-4-27 4:15:04编辑过]

搜索更多相关主题的帖子: class 编程 public 公约数 正整数 
2006-04-27 03:57
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
得分:0 
这是我做的第一题,编译出错,缺少返回语句,大家看是哪里有错:
import java.io.*;
class GreatestCommonDivisor
{
public int getcd(int a,int b)
{
int i,j;
j=(a>b)?b:a;
for(i=j;i>0;i--)
if(a%i==0&&b%i==0)
return i;// 缺少返回语句。
}
public static void main(String args[])
{
try
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=new String();
String str1=new String();
System.out.println("Enter two numbers:");
str=br.readLine();
str1=br.readLine();
int m=Integer.parseInt(str);
int n=Integer.parseInt(str1);
GreatestCommonDivisor cd=new GreatestCommonDivisor();
int e=cd.getcd(m,n);
System.out.println("The Greatest Common Divisor is: "+e);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
2006-04-27 05:34
wtyl0088
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-3-24
收藏
得分:0 

import java.io.*;
public class Gongyueshu {
public int Great(int a,int b){
int c=1;
while(c!=0){

c=a%b;
a=b;
if(c!=0)
b=c;

}
return b;
}
public static void main(String[] args){
Gongyueshu gg=new Gongyueshu();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x=0,y=0;
System.out.println("please input the x and y");
try{
x=Integer.parseInt(br.readLine());
y=Integer.parseInt(br.readLine());
} catch(IOException e){System.out.println(e.getMessage());}

int z=gg.Great(x,y);
System.out.print(z);

}
}


2006-04-27 13:23
happy3stone
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-4-4
收藏
得分:0 

有必要这么麻烦么?

2006-04-27 13:51
wtyl0088
Rank: 1
等 级:新手上路
帖 子:109
专家分:0
注 册:2006-3-24
收藏
得分:0 

麻烦吗


2006-04-27 15:00
★王者至尊★
Rank: 1
等 级:新手上路
帖 子:528
专家分:0
注 册:2006-3-28
收藏
得分:0 
用递归求最大公约数方法
int GCD(int a,int b){
if(a%b==0) //当a除以b的余数为0的时候,返回b
return b;
else
return GCD(b,a%b); //当除不尽的时候,再调用这个方法重复以前的动作
}

------Java 爱好者,论坛小混混,学习中------
2006-04-27 15:13
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

像这种基础的题目应该自己好好想想,而没有必要希望别人能帮你完成


可惜不是你,陪我到最后
2006-04-27 16:58
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
得分:0 
可我就是完成不了啊,否则我也不拿到论坛上问了。

这几道题都是基础题目吗,我怎么觉得这么难哪?
2006-04-27 19:07
xuyijin
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2006-4-13
收藏
得分:0 

这些都是很基础的呀?
我觉得楼主应该多学一点基础的问题!
我就来提示一下吧!
第二题:StringTokenizer getNum=new StringTokenizer(num," ,")//用到字符解析器,至于排序就用选择排序吧,很容易实现的!
第三题:也很简单,用到Properties类就可以轻松实现了!我顺便写了代码,楼主你看看吧!
import java.util.*;
import java.io.*;
public class PropertiesFile {

public static void main(String[] args) {

Properties setting=new Properties();
try
{
setting.load(new FileInputStream("count.txt"));
}
catch(Exception e)
{
setting.setProperty("count",String.valueOf(0));
}
int c=Integer.parseInt(setting.getProperty("count"))+1;//第一次运行时,count=0;
System.out.println("这是第"+c+"次运行");
setting.setProperty("count",String.valueOf(c));
try
{
setting.store(new FileOutputStream("count.txt"),"Program is used:");
}
catch(Exception e)
{
e.printStackTrace();
}

}
}


初学java,希望各位大虾多多指教!!
2006-04-28 15:43
听海★蓝心梦
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2004-11-14
收藏
得分:0 

哈哈………………!!!
俺解决了一个,好高兴啊
虽然简单了点,可是很高兴,毕竟是新手么!!!
大家理解点吧
import java.io.*;
class GreatestCommonDivisor
{
public int getcd(int a,int b)
{
int i,j,m;
m=0;
j=(a>b)?b:a;
for(i=j;i>0;i--)

if(a%i==0&&b%i==0)
m=i;
return m;// 缺少返回语句。

}
public static void main(String args[])
{
try
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=new String();
String str1=new String();
System.out.println("Enter two numbers:");
str=br.readLine();
str1=br.readLine();
int m=Integer.parseInt(str);
int n=Integer.parseInt(str1);
GreatestCommonDivisor cd=new GreatestCommonDivisor();
int e=cd.getcd(m,n);
System.out.println("The Greatest Common Divisor is: "+e);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

[此贴子已经被作者于2006-4-28 16:57:04编辑过]


我的眼里常饱含泪水,因为我对这片土地爱的深沉!QQ:38461725
2006-04-28 16:49
快速回复:几道编程题不会,大家看看要怎么做?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019864 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved