Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 22:27, 1 June 2024
, 25 days agoUpdated for changes in the MediaWiki API and the JDK
JoseAlexis (talk | contribs) |
(Updated for changes in the MediaWiki API and the JDK) |
||
Line 2,577:
=={{header|Java}}==
Tested with Java 1.
<syntaxhighlight lang="java">
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
Line 2,625 ⟶ 2,627:
{
URL url = new
URLConnection rc = url.openConnection();
BufferedReader bfr = new BufferedReader( new InputStreamReader( rc.getInputStream() ) );
Line 2,636:
while( line != null )
{
line = line.trim().replaceAll( "[\",]", "" );
if ( line.startsWith( "
{
// have a programming language - should look like "
languageName = after( after( line, ':' ), ':' ).trim();
}
else if( line.startsWith( "
{
// number of pages the language has (probably)
String pageCount = after( line, '
if( pageCount.compareTo( "
{
// haven't got "
languageList.add( ( (char) Integer.parseInt( pageCount ) ) + languageName );
languageName = "?";
} // if [pageCount.compareTo( "
}
else if( line.startsWith( "
{
// have an indication of wether there is more data or not
gcmcontinue[0] = after( line, '
} // if various line starts
line = bfr.readLine();
Line 2,676:
do
{
String path = ( "
+ "&generator=categorymembers"
+ "&gcmtitle=Category:Programming%20Languages"
Line 2,682:
+ ( gcmcontinue[0].compareTo( "" ) == 0 ? "" : ( "&gcmcontinue=" + gcmcontinue[0] ) )
+ "&prop=categoryinfo"
+ "&format=
);
parseContent( path, gcmcontinue, languageList );
Line 2,708:
} // for lPos
} // main
} // GetRCLanguages
</syntaxhighlight>
{{out}}
Top 10 languages as at
<pre>
1:
3:
4:
5:
6:
7:
8:
9:
10:
...
</pre>
|