中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

Java程序設(shè)計(jì)---實(shí)驗(yàn)2-創(chuàng)新互聯(lián)

1.求任意輸入的10個(gè)數(shù)的和。?

專業(yè)領(lǐng)域包括成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)成都商城網(wǎng)站開(kāi)發(fā)、微信營(yíng)銷、系統(tǒng)平臺(tái)開(kāi)發(fā), 與其他網(wǎng)站設(shè)計(jì)及系統(tǒng)開(kāi)發(fā)公司不同,創(chuàng)新互聯(lián)的整合解決方案結(jié)合了幫做網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗(yàn)和互聯(lián)網(wǎng)整合營(yíng)銷的理念,并將策略和執(zhí)行緊密結(jié)合,為客戶提供全網(wǎng)互聯(lián)網(wǎng)整合方案。
import java.util.Scanner;
public class Test1 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        double sum=0;//定義一個(gè)雙精度浮點(diǎn)數(shù)作為結(jié)果,并設(shè)初值為0
        int input=1;//定義一個(gè)整形input設(shè)初始值為1,防止循環(huán)直接結(jié)束
        System.out.println("請(qǐng)輸入數(shù)字:");
       while(input!=0){//while實(shí)現(xiàn)元素的循環(huán)輸入
           input=sca.nextInt();
           sum+=input;//求和
       }
        System.out.println("sum="+sum);
    }
}

2.實(shí)驗(yàn)題目:獲取三個(gè)整數(shù)中的大值(用三元運(yùn)算符)。

import java.util.Scanner;
public class Test2 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        int a,b,c;
        System.out.println("請(qǐng)輸入要比較的三個(gè)整數(shù):");
        System.out.print("請(qǐng)輸入第一個(gè)數(shù):");
        a=sca.nextInt();
        System.out.print("請(qǐng)輸入第二個(gè)數(shù):");
        b=sca.nextInt();
        System.out.print("請(qǐng)輸入第三個(gè)數(shù):");
        c=sca.nextInt();
        int max= a>b?(a>c?a:c):(b>c?b:c);
        System.out.println("大值為:"+max);
    }
}

3.鍵盤錄入月份的值,輸出對(duì)應(yīng)的季節(jié)。

import java.util.*;
 public class Test3{
    public static void main(String[] args){
        System.out.print("請(qǐng)輸入月份:");
        Scanner sca=new Scanner(System.in);
        int mouth=sca.nextInt();
//        if (mouth == 2 || mouth == 3 || mouth == 4) {
//            System.out.println(mouth + "月是春季");
//        } else if (mouth == 5 || mouth == 6 || mouth == 7) {
//            System.out.println(mouth + "月是夏季");
//        } else if (mouth == 8 || mouth == 9 || mouth == 10) {
//            System.out.println(mouth + "月是秋季");
//        } else if (mouth == 11 || mouth == 12 || mouth == 1){
//            System.out.println(mouth + "月是冬季");
//        }else{
//            System.out.println(mouth + "月不存在");
//        }
        switch(mouth){
            case 2:
            case 3:
            case 4:
                System.out.println(mouth + "月是春季");
                break;
            case 5:
            case 6:
            case 7:
                System.out.println(mouth + "月是夏季");
                break;
            case 8:
            case 9:
            case 10:
                System.out.println(mouth + "月是秋季");
                break;
            case 11:
            case 12:
            case 1:
                System.out.println(mouth + "月是冬季");
                break;
            default:
                System.out.println(mouth + "月不存在");
        }
    }
}

4.輸入年份和月份,輸出該年月的天數(shù)。

import java.util.Scanner;
public class Test4 {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        System.out.print("請(qǐng)輸入年份和月份:");
        int year,month;
        int days=0;
        year=scan.nextInt();
        month=scan.nextInt();
        boolean isLeapYear;
        isLeapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
        switch(month){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days=31;
                break;
            case 2:
                if(isLeapYear){
                    days=29;
                }else{
                    days=28;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days=30;
                break;
            default:
                System.out.println("error!!!");
        }
        System.out.println(year+"年"+month+"月有"+days+"天");
    }
}

5.出租車計(jì)費(fèi)問(wèn)題。

? 開(kāi)封市的出租車計(jì)費(fèi)方式為:起步2公里內(nèi)5元,2公里以上每公里收費(fèi)1.3元,9公里以上每公里收費(fèi)2元,燃油附加費(fèi)1元。

? 編寫程序,輸入公里數(shù),計(jì)算出所需的出租車費(fèi)用。

public class Test5 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        System.out.print("請(qǐng)輸入公里數(shù):");
        int km=sca.nextInt();
        double money;
        if(km<=2){
            money=5;
        }else if(km>2&&km<9){
            money=5+(km-2)*1.3;
        }else{
            money=5+7*1.3+(km-9)*3;
        }
        System.out.println("你所需的出租車費(fèi)用是"+money);
    }
}

6.分別用do-while和for循環(huán)計(jì)算1+1/2!-1/3!+1/4!-1/5!…的前20項(xiàng)之和。

public class Test6 {
    public static void main(String[] args) {
        double a = 1, b = 1;
        double sum = 0;
        System.out.print("do-while循環(huán):");
        do {
            sum += b;
            a++;
            b *= 1.0 / a;
        } while (a<= 20);
        System.out.println(sum);
//       int i,j;
//        for(i=1;i<=20;i++){
//            float t=1;
//            for(j=1;j<=i;j++){
//                t=t*j;
//            }
//            sum+=(1/t);
//        }
        System.out.print("for循環(huán):");
        for (a = 1; a<= 20; a++) {
            b *= (1.0 / a);
            sum += b;
        }
        System.out.println(sum);
    }
}          

7.求1000以內(nèi)的完全數(shù)(一個(gè)數(shù)等于它的因子之和稱為完全數(shù))。

public class Test7 {
    public static void main(String[] args) {
        int i;
        int k=0;
        for(i=1;i<=1000;i++){
            int sum=0;
            for(int j=1;j

8.微信中的一個(gè)問(wèn)題:一筐雞蛋,1個(gè)1個(gè)拿,正好拿完。

2個(gè)2個(gè)拿,還剩1個(gè)。

3個(gè)3個(gè)拿,正好拿完。

4個(gè)4個(gè)拿,還剩1個(gè)。

5個(gè)5個(gè)拿,還差1個(gè)。

6個(gè)6個(gè)拿,還剩3個(gè)。

7個(gè)7個(gè)拿,正好拿完。

8個(gè)8個(gè)拿,還剩1個(gè)。

9個(gè)9個(gè)拿,正好拿完。

問(wèn)筐里最少有多少雞蛋?

public class Test8 {
    public static void main(String[] args) {
        int i=0;
        while (true){
            i++;
            if(i%2==1&&i%4==1&&i%5==4&&i%8==1){
                if(i%3==0&&i%7==0&&i%9==0){
                    if(i%6==3){
                        break;
                    }
                }
            }
        }
        System.out.println("筐里最少有"+i+"個(gè)雞蛋");
    }

9.求六邊形面積,六邊形面積可以通過(guò)下面公式計(jì)算(s是邊長(zhǎng)):

注:使用Math類中的方法計(jì)算tan值。

import java.util.Scanner;
public class Test9 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.print("請(qǐng)輸入邊長(zhǎng):");
        double s = input.nextDouble();//用戶輸入數(shù)據(jù)
        //判斷數(shù)據(jù)的合法性
        if(s<0){
            System.out.println("輸入的數(shù)字不合法");
        }
        //進(jìn)行面積運(yùn)算
        double area = (6 * s * s) / (4 * Math.tan(Math.PI / 6));
        //輸出面積
        System.out.printf("六邊形的面積是:"+area);
    }
}

10.實(shí)現(xiàn)會(huì)員注冊(cè),要求用戶名長(zhǎng)度不小于3,密碼長(zhǎng)度不小于6,若不滿足需有提示信息,提示輸入有誤;注冊(cè)時(shí)兩次輸入密碼必須相同(字符串)。

import java.util.Scanner;
public class Test10 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        String name;
        String password;
        String newpassword;
        System.out.println("用戶注冊(cè)");
            System.out.print("用戶名:");
            name=sca.next();
            System.out.print("設(shè)置密碼:");
           password=sca.next();
            System.out.print("確認(rèn)密碼:");;
           newpassword=sca.next();
            while(name.length()< 3||(password.length())<6||(password.equals(newpassword)==false)){
                if(name.length()<3) {
                    System.out.println("用戶名長(zhǎng)度不得小于3");
                }
                    if(password.length()<6){
                        System.out.println("密碼長(zhǎng)度不得小于6");
                    }
                    if(password.equals(newpassword)==false){
                        System.out.println("兩次密碼不一致");
                    }
                    System.out.print("請(qǐng)重新輸入用戶名:");
                    name = sca.next();
                    System.out.print("請(qǐng)重新輸入密碼:");
                    password = sca.next();
                    System.out.print("請(qǐng)?jiān)俅屋斎朊艽a:");
                    newpassword = sca.next();
            }
        System.out.println("用戶名:"+name);
        System.out.println("密碼:"+password);
        System.out.println("注冊(cè)成功!");
    }
}

11.找出兩個(gè)分教最高的學(xué)生)編寫程序,提示輸入學(xué)生的個(gè)數(shù)、每個(gè)學(xué)生的名字及其分?jǐn)?shù),最后顯示獲得最高分的學(xué)生和第二高分的學(xué)生。

import java.util.Scanner;
public class Test11 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        System.out.print("請(qǐng)輸入學(xué)生的數(shù)量:");
        int n=sca.nextInt();
        if(n<2)
        {
            System.out.println("輸入學(xué)生的個(gè)數(shù)過(guò)少");
            System.exit(0);//結(jié)束程序
        }
        String[] stuname=new String[n];
        int[] score=new int[n];
        for(int i=0;i

12.定義一維數(shù)組并初始化,通過(guò)鍵盤任意輸入一個(gè)數(shù),查找該數(shù)是否存在(結(jié)果返回下標(biāo)值)。

import java.util.Scanner;
public class Test12 {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        int[] arr=new int[]{10,20,30,40,50};
        System.out.print("請(qǐng)輸入你要查找的數(shù)字:");
        int n=sca.nextInt();
        int i=0,p=-1;

//        for(i=0;i=0){
//            System.out.println("所求下標(biāo)為"+p);
//        }else if(p==-1){
//            System.out.println("該數(shù)字未在數(shù)組中。");
//        }
        while(i=0){
            System.out.println("所求下標(biāo)為"+p);
        }else if(p==-1){
            System.out.println("該數(shù)字未在數(shù)組中。");
        }
    }
}   

13.編寫一個(gè)程序,將二維數(shù)組a轉(zhuǎn)置后存入數(shù)組b(所謂轉(zhuǎn)置就是行列互換)例如:

1 2 3

4 5 6

7 8 9 ??

的轉(zhuǎn)置就是:

public class Test13 {
    public static void main(String[] args) {
    int[][] arr1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int[][] arr2=new int[3][3];
      for(int i = 0; i

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧

本文標(biāo)題:Java程序設(shè)計(jì)---實(shí)驗(yàn)2-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://www.2m8n56k.cn/article46/gsshg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司App設(shè)計(jì)小程序開(kāi)發(fā)微信公眾號(hào)外貿(mào)建站網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

主站蜘蛛池模板: 国内一级特黄女人精品片 | 怡红院免费的全部视频 | 97影院理论片 | 好叼操这里只有精品 | 国产成人在线免费观看 | 久久久精品国产免费观看同学 | 亚洲精品免费视频 | 岛国伊人 | 亚洲免费毛片 | 黄色网址在线免费看 | 亚洲一区二区三区四区 | 欧美精品专区55页 | 日本免费网站视频www区 | 国产精品自在欧美一区 | 亚洲一级大片 | 国产精品一区二区三区高清在线 | 国产在线精品成人一区二区三区 | 人成免费a级毛片 | 亚洲欧美激情在线 | 久久香焦 | 可以免费看黄的网址 | 偷拍视频一区在线观看 | 午夜精品久久久久久99热7777 | 欧美一级毛片欧美毛片视频 | 欧美另类精品 | 亚洲毛片免费看 | 一区二区三区四区视频在线 | 成人片网址 | 久久99亚洲精品久久久久 | 在线99视频 | 成年人网站在线观看视频 | 丁香伊人五月综合激激激 | 国产免费自拍视频 | 日韩一级在线播放免费观看 | 久久国产香蕉 | 亚洲男人的天堂久久香蕉 | 成人av手机在线观看 | 成人公开视频 | a级国产乱理伦片在线观看 a级国产乱理伦片在线观看99 | 成人网在线视频 | 特级片免费看 |