Java习题7

Python013

Java习题7,第1张

import java.io.BufferedReader

import java.io.IOException

import java.io.InputStreamReader

import java.net.URL

public class URLReader {

public static void main(String[] args) throws IOException {

URL url = new URL("http://www.baidu.com/")

BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))

String line = null

while((line = br.readLine()) != null) {

System.out.println(line)

}

br.close()

}

}

你了解下哈,你试用的是char类型的哈,你输入的是2转换为ascii的值为50哈,当然答应不出来了,0对应的ascii的值为48,你依次类推,所以你的

if(ch<=9&&ch>=0)

System.out.println("此字符是数字")

应该改为

if(ch<=57&&ch>=48)

System.out.println("此字符是数字")