`
woaiyingyu123
  • 浏览: 69884 次
  • 性别: Icon_minigender_1
  • 来自: 广西
社区版块
存档分类
最新评论

浅谈:)

J# 
阅读更多
一、
for(int i=1,n=0;i<=100;i++){
			if(i%3!=0&&i%7!=0&&i%5!=0){	
				if(n%5==0){	System.out.print("\n");}
				System.out.print("\t"+i);
				n++;
				 continue;
			}	 
			}

n=0不能放在if(n%5==0)的语句内,否则每次循环都会执行一次。这种情况要根据实际题目而定。把n的值赋值为0。n的实际计数意义失效。


二、用Java语句判断数据库表是否存在
  ResultSet rs  = con.getMetaData().getTables(null, null,  "yourTable", null );
  if (rs.next())  {
    //yourTable exist
  }else  {
     //yourTable not exist
 }


三、  
 Vector v=new Vector(); 
            Vector<Vector> vv = new Vector<Vector>(); 
             for(int i=0;i<2;i++){ 
	v=new Vector();//new放这里可更新(清空)v
               for(int j=0;j<2;j++){ 
                  v.addElement("a"); 
         } 
             //  vv.addElement(new Vector(v)); //这里的new很重要。创建新的v对象。//否则如果无new。vv会随着v改变而改变
             
             } 
         System.out.println(vv.toString());  

因为v vv都是Vector的实例,Vector算是对象吧。如果不new Vector(v)。而只是用v。v都是一样的。没有new出。那么打印出的 vv会随v改变而改变。也许就是传址类似过程吧
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics