zoukankan      html  css  js  c++  java
  • Java循环和条件

        下列程序的输出结果是什么?

    1、Java循环和条件

    /**
     * @Title:IuputData.java
     * @Package:com.you.data
     * @Description:TODO
     * @Author: 游海东
     * @date: 2014年3月16日 下午10:18:46
     * @Version V1.2.3
     */
    package com.you.data;
    
    /**
     * @类名:IuputData
     * @描述:TODO
     * @Author:Administrator
     * @date: 2014年3月16日 下午10:18:46
     */
    public class IuputData 
    {
    	/**
    	 * @Title : main
    	 * @Type : IuputData
    	 * @date : 2014年3月16日 下午10:18:47
    	 * @Description : TODO
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		for(int i=0;i<100;i++)
    			Integer inte = new Integer(i);
    		System.out.println("YouHaidong");
    
    	}
    
    }
    
       运行Java Application,出现错误:

    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    	Syntax error, insert "AssignmentOperator Expression" to complete Assignment
    	Syntax error, insert ";" to complete Statement
    	Integer cannot be resolved to a variable
    	inte cannot be resolved to a variable
    	i cannot be resolved to a variable
    
    	at com.you.data.IuputData.main(IuputData.java:29)
    

           局部变量声明的作用范围是在一个块内,for循环仅限于执行语句。

        由于这段代码中的Integer inte 的作用范围在整个main方法中,这样就造成了变量重复定义,

        出现程序编译错误

    2、正确的做法

    /**
     * @Title:IuputData.java
     * @Package:com.you.data
     * @Description:TODO
     * @Author: 游海东
     * @date: 2014年3月16日 下午10:18:46
     * @Version V1.2.3
     */
    package com.you.data;
    
    /**
     * @类名:IuputData
     * @描述:TODO
     * @Author:Administrator
     * @date: 2014年3月16日 下午10:18:46
     */
    public class IuputData 
    {
    	/**
    	 * @Title : main
    	 * @Type : IuputData
    	 * @date : 2014年3月16日 下午10:18:47
    	 * @Description : TODO
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		for(int i=0;i<100;i++)
    		{
    			Integer inte = new Integer(i);
    		}
    		System.out.println("YouHaidong");
    	}
    
    }
    

    输出:YouHaidong

  • 相关阅读:
    js中return的作用
    jstl标签详解总结
    css——overflow属性用法
    oracle数据批处理
    SQL Server 2000/2005 分页SQL — 单条SQL语句
    dataset和实体类 之间的转换
    barmanager设置
    C#集合类(HashTable, Dictionary, ArrayList)与HashTable线程安全
    comboboxEdit 不能输入,只能选择
    C#在父窗口中调用子窗口的过程(无法访问已释放的对象)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315300.html
Copyright © 2011-2022 走看看