Java loops and conditions

Source: Internet
Author: User

What are the output results of the following programs?

1. Java loops and conditions

/*** @ Title: IuputData. java * @ Package: com. you. data * @ Description: TODO * @ Author: youhaidong * @ date: 10:18:46, January 1, March 16, 2014 * @ Version V1.2.3 */package com. you. data;/*** @ Class Name: IuputData * @ Description: TODO * @ Author: Administrator * @ date: march 16, 2014 10:18:46 */public class IuputData {/*** @ Title: main * @ Type: IuputData * @ date: March 16, 2014 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 ");}}
An error occurred while running Java Application:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error, insert "AssignmentOperator Expression" to complete AssignmentSyntax error, insert ";" to complete StatementInteger cannot be resolved to a variableinte cannot be resolved to a variablei cannot be resolved to a variableat com.you.data.IuputData.main(IuputData.java:29)

The scope of the local variable declaration is within a block, and the for loop is limited to execution statements.

Since the Integer inte in this code is used in the entire main method, the variable definition is repeated,

An error occurred while compiling the program.

2. correct practices

/*** @ Title: IuputData. java * @ Package: com. you. data * @ Description: TODO * @ Author: youhaidong * @ date: 10:18:46, January 1, March 16, 2014 * @ Version V1.2.3 */package com. you. data;/*** @ Class Name: IuputData * @ Description: TODO * @ Author: Administrator * @ date: march 16, 2014 10:18:46 */public class IuputData {/*** @ Title: main * @ Type: IuputData * @ date: March 16, 2014 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 ");}}

Output: YouHaidong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.