java练习程序1
/*import javax.swing.JFrame;*/
/*import javax.swing.JOptionPane;*/
public class TestFrame{
public static void main(String[] args) throws Exception{
/*JFrame frame1 = new JFrame();
frame1.setTitle("Windows 1");
frame1.setSize(200,150);
frame1.setLocation(200,100);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setVisible(true);
JFrame rx = new JFrame();
rx.setTitle("rx's Windows");
rx.setSize(300,300);
rx.setLocation(0,0);
rx.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
rx.setVisible(true);*/
/*String s = "Welcome to java";
String s1 = new String("Welcome to java");
String s2 = s1.intern();
String s3 = "Welcome to java";
System.out.println("s1 == s is" + (s1 == s));
System.out.println("s2 == s is" + (s2 == s));
System.out.println("s.intern() == s3.intern() is" + (s.intern() == s3.intern()));
String s4 = "Welcome";
String s5 = "j a v a";
System.out.println();
System.out.println(s4.toLowerCase());
System.out.println(s4.toUpperCase());
System.out.println(s5.trim());
System.out.println(s4.replace('e','A'));
System.out.println(s4.replaceAll("e","E"));*/
/*System.out.println("Welcome to java".indexOf('W'));
System.out.println("Welcome to java".indexOf('o'));
System.out.println("Welcome to java".indexOf('o',5));
System.out.println("Welcome to java".indexOf("come"));
System.out.println("Welcome to java".indexOf("java",5));
System.out.println("Welcome to java".indexOf("Java",5));
System.out.println("Welcome to java".lastIndexOf('W'));
System.out.println("Welcome to java".lastIndexOf('o'));
System.out.println("Welcome to java".lastIndexOf('o',5));
System.out.println("Welcome to java".lastIndexOf("come"));
System.out.println("Welcome to java".lastIndexOf("java",5));
System.out.println("Welcome to java".lastIndexOf("Java",5));*/
/*char[] chars = "Java".toCharArray();
getChars(int srcBegin,int
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
本示例从网上下载一本小说,并保存为 UTF-8 格式。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException;
......
第一种:
Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
}
效率高,以后一定要使用此种方式!
第二种:
Map map = new HashMap();
Iterato ......
importjava.text.DecimalFormat;
publicclassTestNumberFormat{
publicstaticvoidmain(String[]args){
doublepi=3.1415927; //圆周率
//取一位整数
System.out.println(newDecimalFormat("0").format(pi)); //3
//取一位整数和两位小数
System ......
十进制转成十六进制:
Integer.toHexString(int i)
十进制转成八进制
Integer.toOctalString(int i)
十进制转成二进制
Integer.toBinaryString(int i)
十六进制转成十进制
Integer.valueOf("FFFF",16).toString()
八进制转成十进制
Integer.valueOf("876",8).toString()
二进制转十进制
Intege ......