import java.util.HashMap;
public class Test
{
public static void main(String[] args)
{
// 打算以空间换时间,仅遍历一次, 也可以少定义变量,但是多做几次循环
final int category = 5; // 假设有"装订类别", "书籍语言", "功能类别", "适合人群",
// "图书类别"这5个类别
HashMap<String, Integer> map1 = new HashMap<String, Integer>();
HashMap<String, Integer> map2 = new HashMap<String, Integer>();
HashMap<String, Integer> map3 = new HashMap<String, Integer>();
HashMap<String, Integer> map4 = new HashMap<String, Integer>();
HashMap<String, Integer> map5 = new HashMap<String, Integer>();
int max1 = 0, max2 = 0, max3 = 0, max4 = 0, max5 = 0;
String max1s, max2s, max3s, max4s, max5s;
max1s = max2s = max3s = max4s = max5s = null;
String str = "装订类别-精装@书籍语言-中文@功能类别-社会科学@适合人群-全部@图书类别-科幻\n"
+ "装订类别-精装@书籍语言-中文@功能类别-基础科学@适合人群-学生@图书类别-文艺\n"
+ "装订类别-精装@书籍语言-英文@功能类别-社会科学@适合人群-学生@图书类别-文艺\n"
+ "装订类别-简装@书籍语言-中文@功能类别-社会科学@适合人群-学生@图书类别-文艺";
String[] strs = str.split("@|\n"); // 假设每行以\n结束,如果是\r\n,则str.split("@ | \r\n");
for (int i = 0; i != strs.length; ++i)
{
switch (i % category)
{
case 0:
{
Integer v = map1.get(strs[i]);
if (v == null)
v = 1;
else
v += 1;
map1.put(strs[i], v);
if (v > max1)
{
max1 = v;
max1s = strs[i];
}
}
break;
case 1:
{
Integer v = map2.get(strs[i]);
if (v == null)
v = 1;
else
v += 1;
map2.put(strs[i], v);
if (v > max2)
{
max2 = v;
max2s = strs[i];
}
}
break;
case 2:
{
Integer v = map3.get(strs[i]);
if (v == null)
v = 1;
else
v += 1;
map3.put(strs[i], v);
if (v > max3)
{
max3 = v;
max3s = strs[i];
}
}
break;
case 3:
{
Integer v = map4.get(strs[i]);
if (v == null)
v = 1;
else
v += 1;
map4.put(strs[i], v);
if (v > max4)
{
max4 = v;
max4s = strs[i];
}
}
break;
case 4:
{
Integer v = map5.get(strs[i]);
if (v == null)
v = 1;
else
v += 1;
map5.put(strs[i], v);
if (v > max5)
{
max5 = v;
max5s = strs[i];
}
}
break;
}
}
System.out.println("A=" + max1s.split("-")[1] + " B=" + max2s.split("-")[1] + " C="
+ max3s.split("-")[1] + " D=" + max4s.split("-")[1] + " E=" + max5s.split("-")[1]);
}
}
追问前面那个追问是我晕掉了
修正下
String sql="select extbei from pros where id in ( select pid from tjqz where uname='by01')";
怎么样把这边提取出的数据
代替掉这里String str = "装订类别-精装@书籍语言-中文@功能类别-社会科学@适合人群-全部@图书类别-科幻"
后面举例用的内容啊。。。。。
追答你这个数据能整个复制吗?
你懂怎么把数据导入到.sql文件吧?把它导入进去复制;
我这边稍微改一下,方便你粘贴.
实在不能的话,告诉我是什么数据库.
追问装订类别-精装@书籍语言-中文@功能类别-社会科学@适合人群-学生@图书类别-文艺
装订类别-精装@书籍语言-中文@功能类别-社会科学@适合人群-学生@图书类别-文艺
装订类别-精装@书籍语言-中文@功能类别-社会科学@适合人群-学生@图书类别-文艺
整个复制也就这样但是extbet这个字段是动态的随时可能会加入更多的数据不是定死的所以我想通过sql语句的结果对str赋值但是不会。。。。。
mysql
追答那你那有mysql的java驱动吧
追问有的
就是如果我仅仅查询这些数据是正常可以输出的
你提供的java也是可以正常运行的
但是通过sql语句查询出的数据放到你给的java中初始string str赋值那一段我不知道要怎么放
我就是想解决这一点
追答你给我一份mysql的驱动,我给你jdbc
追问是要这个么?
我把表也附上了