zoukankan      html  css  js  c++  java
  • hw1 problem1

    hw1 problem1

    用inputline替代X用了String里的replace()method;后来看陈同学的code发现可以用"+inputline+" 直接替代啊,之前都不造。还有URL好多method都不太明白什么意思,有好的学习API的方法吗,求分享。

    code:

    class OpenCommercial {

      /** Prompts the user for the name X of a company (a single string), opens

       *  the Web site corresponding to www.X.com, and prints the first five lines

       *  of the Web page in reverse order.

       *  @param arg is not used.

       *  @exception Exception thrown if there are any problems parsing the 

       *             user's input or opening the connection.

       */

      public static void main(String[] arg) throws Exception {

        BufferedReader keyboard;

        String inputLine;

        keyboard = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Please enter the name of a company (without spaces): ");

        System.out.flush();        /* Make sure the line is printed immediately. */

        inputLine = keyboard.readLine();

        String originalWibeSite="http://www.x.com/";

        String newWibeSite=originalWibeSite.replaceAll("x",inputLine);//replace x with inputline

        URL x=new URL(newWibeSite);

        InputStream ins=x.openStream();

        InputStreamReader isr=new InputStreamReader(ins);

        BufferedReader bfr=new BufferedReader(isr);

        String lines[]=new String[5];

      int i=0;

      while(i<5){

      lines[i]=bfr.readLine();

      i++;}

      int j=4;

      while(j>=0){

      System.out.println(lines[j]);  

      j--;

      }

       

        /* Replace this comment with your solution.  */

     

      }

     

      

    }

    output: 

    Please enter the name of a company (without spaces): moldirkorea

    </script>

    //-->

    location.href = "./kr/";

    <!--

    <script type="text/javascript">

  • 相关阅读:
    图标插件——heightcharts
    垂直居中——登录界面
    javaEE(web开发)私人学习笔记
    javaSE(java基础库)私人学习笔记
    commons-fileupload(apache开源文件上传组件)使用方式
    fastjson与spring mvc整合的配置
    ehcache的xml配置
    dubbo用于传输数据的bean必须有空构造器的原因
    修复dubbo注解与spring aop冲突的问题
    dom4j(XML解析)私人学习笔记
  • 原文地址:https://www.cnblogs.com/Jingjunw/p/7182457.html
Copyright © 2011-2022 走看看