`
zhuobinzhou
  • 浏览: 133803 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
文章列表
inter()方法会先检查String池中是否存在字符部分相同的字符串对象,如果有就返回。   /* * 作者:阳光的味道 * 功能:示范String类的对象的intern()方法 * 日期:2010/11/07 * */ public class TesStringIntern { public static void main(String args[]){ String str1 = "1"; String str2 = "2"; String str3 = "12"; Strin ...
import java.util.Scanner; public class TestArray { /* * 作者:阳光的味道 * 功能:动态配置数组长度,并处理数组成员 * 日期:2010/11/06 * */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请配置数组的长度:"); int length = scanner.nextInt(); fl ...
public class NineTable { public static void main(String args[]){ for(int i = 1 ; i < 10 ; i ++){ for(int j = 1 ; j <= i ; j ++){ System.out.printf("%d*%d=%2d ",i,j,i*j); } System.out.println(); } } }   1*1= 1 2*1= 2 2*2= 4 3*1= 3 3*2= 6 3*3= 9 4*1= 4 4* ...
1、使用System.in 使用标准输入System.in对象提供的read()方法读取来自命令行窗口的数据,每一次仅能读取一个字节的数据,并且返回该字节的整数值。   import java.io.IOException; public class TestSystemIn { /* * 作者:阳光的味道 * 功能:示范System.in方法 * 日期:2010/11/06 * */ public static void main(String[] args) { // TODO Auto-generated method stub ...
/* * 作者:阳光的味道 * 功能:示范printf()方法 * 日期:2010/11/06 * */ public class Demo { public static void main(String[] args) { //指定参数输出 System.out.printf("This is a %s !","String").println();//打印换行符 System.out.printf("%d is a data!",100).println(); } }  
main()是Java程序的入口,程序的执行是由此入口开始的。   类中的方法是类的成员,main()方法一定是public成员。这样它才可以在执行环境中调用。   main()方法不需要产生对象就能够被执行,故其必须是static成员。   void表示main()执行结果不返回任何职。   String args[]用来接受命令行参数。
import java.io.File; import java.util.ArrayList; public class FileDemo { public static void main(String args[]){ try{ File file = new File(args[0]); File fileCom = new File("D:\\4thDownloads\\c.txt"); System.out.println( file.compareTo(fileCom));//按字典排序判断路径的位置 ...
public class Demo2 { static String str = new String("I love you!"); public static void main(String args[]){ //使用public boolean isEmpty() if(!str.isEmpty()){ System.out.println(str); }else{ System.out.println("There is no text to show"); } //out:I love y ...
public class Demo1 { //I'm zhuobinzhou //不加static,将报错:Cannot make a static reference to the non-static field str static String str = new String();//使用String()创建一个空字符序列 static String str1 = new String("I'm"); static char[] ch = new char[]{' ','z','h','u','o'}; static String str ...
//定义一个抽象类 abstract class A { abstract public void fun1(); } class Outer { public static void main(String[] args) { //定义一个继承自抽象类的内部类 class Inner extends A{ //覆写抽象方法 public void fun1(){ System.out.println("public void fun1()"); } } //创建一个匿名外部类并调用一个外部类方法 ...
import java.util.Random; public class StringTest { public static void ini(String[] s){ //为数组初始化 for(int j = 0 ; j < s.length ; j ++){ for(int i = 0 ; i < s.length ; i ++){ s[i]= "I love you !" ; } } for(int i = 1 ; i <= s.length ; i ++){ System.ou ...
class testArray{ public static void main(String args[]){ for(String s : args){ //args接受从DynamicArray类中传递过来的字符串 System.out.println(s); } } } public class DynamicArray{ public static void main(String args[]){ testArray.main(new String[]{"hey,man!","I'm a method o ...
Java程序中一句连续的字符串不能分开在两行中写。可以用+来进行分解。在Eclipse中在输好的字符串中,将光标停于你想要分解的地方,然后按下Enter,它就会自动生成+功能。   中文分号是不能作为执行语句的结束标志的,英文分号才可以。   /*    */中可以嵌套//注释,但不能嵌套/*   */。   \b表示退格键,相当于Back Space
import java.util.Random; public class ArraysTest{ public static void main(String args[]){ Random ran = new Random(); //创建长为随机整数(小于10)的整数型数组 int[] a = new int[ran.nextInt(10)]; System.out.println("the length of array a = " + a.length); for(int x : a){ x = ran.ne ...
public class Test09 { private int x = 18 ; public void fun(Test09 t){ System.out.println(t.x); } public static void main(String[] args) { new Test09().fun(new Test09()); } }  效果: 18
Global site tag (gtag.js) - Google Analytics