浏览代码

Lab 2 pre-demo

Thomas Flucke 10 年之前
父节点
当前提交
a3b90a4538
共有 5 个文件被更改,包括 98 次插入0 次删除
  1. 6 0
      Lab2/.classpath
  2. 17 0
      Lab2/.project
  3. 12 0
      Lab2/.settings/org.eclipse.jdt.core.prefs
  4. 二进制
      Lab2/bin/Separator.class
  5. 63 0
      Lab2/src/Separator.java

+ 6 - 0
Lab2/.classpath

@@ -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 - 0
Lab2/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab2</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 - 0
Lab2/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Wed Sep 23 11:13:37 PDT 2015
+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

二进制
Lab2/bin/Separator.class


+ 63 - 0
Lab2/src/Separator.java

@@ -0,0 +1,63 @@
+import java.util.Arrays;
+import java.util.Scanner;
+
+
+public class Separator {
+
+	public static void main(String[] args) 
+	{
+		int n = 5;
+		
+		int[] intArray = new int[n];
+		float[] floatArray = new float[n];
+		
+		System.out.println("Please input values here:");
+		
+		Scanner scannerRead = new Scanner(System.in);
+		scannerRead.useDelimiter("\\s");
+		
+		int intIndex = 0;
+		int floatIndex = 0;
+		
+		boolean runLoop = true;
+		
+		while(runLoop)
+		{
+			if (scannerRead.hasNextInt())
+			{
+				if (intIndex >= n)
+				{
+					runLoop = false;
+				}
+				else
+				{
+					intArray[intIndex] = scannerRead.nextInt();
+					intIndex++;
+				}
+			}
+			else if (scannerRead.hasNextFloat())
+			{
+				if (floatIndex >= n)
+				{
+					runLoop = false;
+				}
+				else
+				{
+					floatArray[floatIndex] = scannerRead.nextFloat();
+					floatIndex++;
+				}
+			}
+			else
+			{
+				runLoop = false;
+			}
+			
+		}
+		
+		System.out.println("Abort mission");
+		System.out.println("Integers: "+Arrays.toString(intArray));
+		System.out.println("Floats: "+Arrays.toString(floatArray));
+		
+	}
+
+}