zoukankan      html  css  js  c++  java
  • CS61b homework1

    Programe1:根据输入建立URL,读取其网站前五行内容并输出,代码:

    import java.io.*;
    import java.net.URL;
    public class programe1{
    public static String reverse(String s){
    int len=s.length();
    StringBuffer sb=new StringBuffer(len);
    for(int i=(len-1);i>=0;i--){
    sb.append(s.charAt(i));
    }
    return sb.toString();
    }//reverse String方法,感觉比较笨,不过也确实想不出其他的了.。。。
    public static void main(String[]args) throws IOException{
    String inputLine;
    BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter the name of a company (without spaces): ");
    System.out.flush();
    inputLine=keyboard.readLine();
    URL url=new URL("http://www."+inputLine+".com/");
    InputStreamReader streamreader=new InputStreamReader(url.openStream());
    BufferedReader webReader=new BufferedReader(streamreader);
    for(int i=0;i<5;i++){
    String a=webReader.readLine();
    String b=reverse(a);
    System.out.println(b);
    }
    
    }
    }

    运行结果:

    Programe2:输入String,去掉其第二个元素输出:

    代码:

    import java.io.*;
    
    public class Programe2 {
    public static String change(String s){
    char[]c=s.toCharArray();
    String s1="";
    s1+=c[0];
    for(int i=2;i<c.length;i++)
    s1+=c[i];
    return s1;
    }
    public static void main(String[]args) throws IOException{
    BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter your words: ");
    System.out.flush();
    String s=keyboard.readLine();
    String output=change(s);
    System.out.print(output);
    
    }
    
    }

    输出结果:

     

  • 相关阅读:
    MySQL数据库之数据类型
    MySQL数据库之数据操作
    MySQL数据库之表的操作
    十、原子操作
    九、std::async异步线程
    八、条件变量
    cisco笔试记录
    七、单例设计模式
    基于HTTP的功能追加协议
    使用栈来计算后缀表达式
  • 原文地址:https://www.cnblogs.com/lyz1995/p/7143577.html
Copyright © 2011-2022 走看看