现在进行推荐的第三步:
1:利用数据的格式如下:
2:编程语言采用的是Java,源代码如下:
package top10;
import java.util.*;
import java.io.*;
public class top {
public static void top(String []one,String []two,String []three){
int []one1 = new int[15688];
for(int i =0;i<15687;i++)
{
one1[i]=0;
for(int j=i;j<15688;j++)
if(one[j]==one[i])
{
one1[i]++;
}
}
for(int i =0;i<15688;i++)
for(int j=i;j<15688;j++)
if(one1[i]>one1[j])
{
String temp1;
temp1=one[i];
one[i]=one[j];
one[j]=temp1;
String temp2;
temp2=two[i];
two[i]=two[j];
two[j]=temp2;
String temp3;
temp3=three[i];
three[i]=three[j];
three[j]=temp3;
}
System.out.println("Top前十的结果为:");
System.out.println("姓名\t"+"\t推荐博客地址"+"\t\t\t\t\t\t\t\t\t\t\t"+"推荐作者博客首地址");
for(int k=1;k<=10;k++)
{
String str;
str = String.format("%s\t\t%s\t\t%s", one[k],two[k],three[k]);
System.out.println(str);
}
}
public static void list() throws IOException{
FileReader in = new FileReader("title.txt");
BufferedReader br = new BufferedReader(in);
String s1 = null;
String []one = new String[15688];
String []two = new String[15688];
String []three = new String[15688];
int i = 0,k=0,m=0,j = 1;
while((s1 = br.readLine()) != null) {
if(j%3==2)
{
two[k] = s1;
k++;
}
else if(j%3==0)
{
three[m] = s1;
m++;
}
else
{
one[i] = s1;
i++;
}
j++;
}
br.close();
in.close();
// System.out.println(j);
top(one,two,three);
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println("+++++++++++++++++|||||||||||||||++++++++++++++++++");
System.out.println("**************欢迎使用新浪明星博客推荐系统 ***************");
System.out.println("************** 1、使用推荐功能 ***************");
System.out.println("************** 2、退出此系统,谢谢使用 ***************");
System.out.println("+++++++++++++++++|||||||||||||||++++++++++++++++++");
Scanner in = new Scanner(System.in);
while(true)
{
int i = in.nextInt();
{
switch(i)
{
case 1: list();break;
case 2:System.out.println("谢谢使用!!!");break;
default:System.out.println("请重新输入!!!");
}
}
}
}
}
3:运行的结果如图: