Initial Commit
This commit is contained in:
6
Java/EnhancedForLoop/.classpath
Normal file
6
Java/EnhancedForLoop/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Java/EnhancedForLoop/.project
Normal file
17
Java/EnhancedForLoop/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EnhancedForLoop</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
12
Java/EnhancedForLoop/.settings/org.eclipse.jdt.core.prefs
Normal file
12
Java/EnhancedForLoop/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,12 @@
|
||||
#Sun Nov 21 11:27:11 EST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
BIN
Java/EnhancedForLoop/bin/Main.class
Normal file
BIN
Java/EnhancedForLoop/bin/Main.class
Normal file
Binary file not shown.
58
Java/EnhancedForLoop/src/Main.java
Normal file
58
Java/EnhancedForLoop/src/Main.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @author Twenty Codes, LLC
|
||||
* @author ricky barrette
|
||||
* @date Nov 21, 2010
|
||||
*/
|
||||
|
||||
/**
|
||||
* this class will be used to demonstrate an enhanced for loop that is discussed here
|
||||
* http://download.oracle.com/javase/tutorial/java/nutsandbolts/for.html
|
||||
* We recommend using this form of the for statement instead of the general form whenever possible
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
static int[] array = new int[] { 1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10};
|
||||
static char[] helloWorld = new char[] { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
|
||||
|
||||
/**
|
||||
* called when the application is first started
|
||||
* @param args
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* the way this works is that you provide 2 arguments for the for loop.
|
||||
*
|
||||
* the first is the object to hold an item in the array, and the second is the array it self.
|
||||
*
|
||||
* the to are separated by a colon.
|
||||
*
|
||||
* the output for this for loop will be:
|
||||
* 1
|
||||
* 2
|
||||
* 3
|
||||
* 4
|
||||
* 5
|
||||
* 6
|
||||
* 6
|
||||
* 6
|
||||
* 7
|
||||
* 8
|
||||
* 9
|
||||
* 10
|
||||
*/
|
||||
for(int item : array){
|
||||
System.out.println(item);
|
||||
}
|
||||
|
||||
/*
|
||||
* here is another example, this time with a char array
|
||||
*/
|
||||
for(char character : helloWorld){
|
||||
System.out.print(character);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user