第二次实验课代码
添加ScannerDomo和NumberProcessor
This commit is contained in:
11
C02 Expresion/C02 Expresion.iml
Normal file
11
C02 Expresion/C02 Expresion.iml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
21
C02 Expresion/src/NumberProcessor.java
Normal file
21
C02 Expresion/src/NumberProcessor.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class NumberProcessor {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("请输入一个三位或四位整数");
|
||||||
|
int number = sc.nextInt();
|
||||||
|
if(number%100>0 && number%100<10){
|
||||||
|
while(number>0){
|
||||||
|
System.out.println(number%10);
|
||||||
|
number=number/10;
|
||||||
|
}
|
||||||
|
} else if(number<0)
|
||||||
|
System.out.println("请重新输入一个正整数");
|
||||||
|
else {
|
||||||
|
System.out.println("请重新输入一个三位或四位整数");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
29
C02 Expresion/src/ScannerDemo.java
Normal file
29
C02 Expresion/src/ScannerDemo.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ScannerDemo {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("请输入姓名:");
|
||||||
|
String name = sc.next();
|
||||||
|
|
||||||
|
System.out.println("请输入年龄:");
|
||||||
|
int age = sc.nextInt();
|
||||||
|
|
||||||
|
System.out.println("请输入性别:");
|
||||||
|
char sex = sc.next().charAt(0);
|
||||||
|
|
||||||
|
System.out.println("请输入身高:");
|
||||||
|
double height = sc.nextDouble();
|
||||||
|
|
||||||
|
System.out.println("婚否:");
|
||||||
|
boolean isMarried = sc.nextBoolean();
|
||||||
|
|
||||||
|
System.out.println("姓名"+name);
|
||||||
|
System.out.println("年龄"+age);
|
||||||
|
System.out.println("性别"+(sex=='m'||sex=='M'?"男":"女"));
|
||||||
|
System.out.println("身高"+height);
|
||||||
|
System.out.println("婚否:"+(isMarried?"已婚":"未婚"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
ClassOfJava.iml
Normal file
11
ClassOfJava.iml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
src/Main.java
Normal file
6
src/Main.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello,World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user