標籤:
| 步驟 |
耗時h |
百分比% |
| 需求分析 |
0.3h |
7.5 |
| 設計 |
2.5h |
62.5 |
| 代碼實現 |
0.5h |
12.5 |
| 測試 |
0,2h |
5 |
| 分析總結 |
0.5h |
12.5 |
實驗一
實驗二:
實驗三
實現四則運算
代碼:
import java.util.Scanner;
public class D1_jisuanqi {
public static void main(String[] args){
double x,y,s;
int i;
System.out.println("1是乘法,2是除法,3是加法,4是減法,5是模數");
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
if (i == 1)
{
System.out.println("你將用乘法");
System.out.println("請輸入x,y兩個值:(用空格間隔)");
Scanner c = new Scanner(System.in);
x = c.nextDouble();
y = c.nextDouble();
s = x*y;
System.out.println("x*y的值是:"+s);
c.close();
}
else if (i == 2)
{
System.out.println("你將用除法");
System.out.println("請輸入x,y的值:(用空格間隔)");
Scanner d = new Scanner(System.in);
x = d.nextDouble();
y = d.nextDouble();
s = x/y;
System.out.println("x/y的值是:"+s);
d.close();
}
else if (i == 3)
{
System.out.println("你將用加法");
System.out.println("請輸入x,y的值:(用空格間隔)");
Scanner e = new Scanner(System.in);
x = e.nextDouble();
y = e.nextDouble();
s = x+y;
System.out.println("x+y的值是:"+s);
e.close();
}
else if(i == 4)
{
System.out.println("你將用減法");
System.out.println("請輸入x,y的值:(用空格間隔)");
Scanner f = new Scanner(System.in);
x = f.nextDouble();
y = f.nextDouble();
s = x-y;
System.out.println("x-y的值是:"+s);
f.close();
}
else
{
System.out.println("你將用模數");
System.out.println("請輸入x,y的值(用空格間隔)");
Scanner g = new Scanner(System.in);
x = g.nextDouble();
y = g.nextDouble();
s = x%y;
System.out.println("x%y的值是:"+s);
g.close();
}
sc.close();
}
}
package ljp;
import java.util.Scanner;
public class Hello {
public static void main(String[] agrs){
System.out.println("Input your first name,please:");
Scanner s =new Scanner(System.in);
String name = s.next();
System.out.println("Hello"+name+"!");
}
java 實驗一