一个简单的由C语言改写为java的程序

[复制链接]
查看11 | 回复3 | 2008-10-28 23:33:00 | 显示全部楼层 |阅读模式
我想实现输入三个字符串,然后比较他们之间的大小关系 ,然后输出
一下是C语言的语句,以提供各位参考:
#include
#include
void main()
{
char string[20];
char str[3][20];
int i;
for(i=0;i0)strcpy(string,str[0]);
else strcpy(string,str[1]);
if(strcmp(str[2],string)>0) strcpy(string,str[2]);
printf("\n the largest String is:",string);
}
//C语言实现的大概就是这样,我希望在java中用二维数组的方式去实现,如果此C语言的程序无法运行,只需稍作修改即可,原理并无错,目的只是供大家参考,谢谢
}

回复

使用道具 举报

千问 | 2008-10-28 23:33:00 | 显示全部楼层
public class Test{public static void main(String[] args){
String[] string = new String[20]; //java得数组必须new一次,自己看吧。
String[][] str = new String[3][20];
int i;
for(i=0;i0) strcpy(string,str[0]); //strcmp和strcpy不知道用java里得...
回复

使用道具 举报

千问 | 2008-10-28 23:33:00 | 显示全部楼层
直接调用String中的compareTo(String str);这个方法不行吗?...
回复

使用道具 举报

千问 | 2008-10-28 23:33:00 | 显示全部楼层
基本是一样的,改改开头和定义,,...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行