jdk中的demo,就是告诉用户使用jdk的一些例子.
要想运行某个.class文件,比如A.class 请运行命令: java A 不要带后缀名.
要想在CMD下运行.jar文件,比如A.jar 请运行命令: java -jar A.jar
某个.class 文件不能被执行,可能是这个.class 没有main方法(程序入口);
---随便在网上一搜一大把
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class URLAccess {
public static void main(String[] args) {
try {
test();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
}
public static void test() throws IOException {
URL url = new URL("");
System.out.println("==================以下为网站内容==================");
URLConnection urlcon = url.openConnection();
int i = urlcon.getContentLength();
if (i 0) {
InputStream is = urlcon.getInputStream();
int a;
while ((a = is.read()) != -1) {
System.out.print((char) a);
is.close();
} else {
System.out.println("响应内容为空...");
运行代码
具体的代码如下:
import java.util.HashMap;
public class SearchDemo {
public HashMapInteger,Integer countMap(char[] arr){
HashMap countMap = new HashMapInteger, Integer();
for (int i = 0; i arr.length; i++) {
if(!countMap.containsKey(arr[i])){
countMap.put(arr[i],1);
}else{
int value = (int)countMap.get(arr[i]) + 1;
countMap.put(arr[i],value);
return countMap;
int count = new SearchDemo().countMap(arr).get('A');
System.out.println("其中'A'字符的个数是:" + count);
运行结果
以上就是土嘎嘎小编为大家整理的javademo代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!