java 實驗一

來源:互聯網
上載者:User

標籤:

 
 步驟 耗時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 實驗一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.