zoukankan      html  css  js  c++  java
  • 【0703作业】猜数游戏

     1 package com.workprojects;
     2 /**
     3  * 猜数游戏
     4  * 数列:8,4,2,1,23,344,12
     5  * 循环输出数列的值,求数列中所有值的和
     6  * 从键盘任意输入一个数据,判断数列中是否含有次数
     7  * 2019-07-03
     8  * @author L
     9  */
    10 
    11 import java.util.Scanner;
    12 
    13 public class Work070301 {
    14     static Scanner sc = new Scanner(System.in);
    15     public static void main(String[] args) {
    16         int[]nums=new int[] {8,4,2,1,23,344,12};//数列的值
    17         System.out.println("—————猜数游戏—————");
    18         System.out.print("请输入您猜的数字:");
    19         int num=sc.nextInt();//输入猜的数字
    20         int sum = 0;//数列总和
    21         boolean flag = false;//判断
    22         for(int i=0;i<nums.length;i++) {
    23             if(num==nums[i]) {
    24                 flag =true;
    25             }
    26         }
    27         System.out.println("本次游戏所含有的数字为:");
    28         for(int num1:nums) {
    29             sum+=num1;
    30             System.out.print(num1+"	");
    31         }
    32         if(flag) {
    33             System.out.println();
    34             System.out.println("***恭喜您,猜对了!***");
    35         }else {
    36             System.out.println();
    37             System.out.println("***很遗憾,您猜错了!***");
    38         }
    39         System.out.println("本次游戏的所有数值之和为:"+sum);
    40     }
    41 }
  • 相关阅读:
    UVa 482
    UVa 10360
    UVa 10812
    UVa 10420
    UVa 573
    UVa 357
    UVa 147
    UVa 674
    郑厂长系列故事——逃离迷宫 HDU4524
    威威猫系列故事——过生日 HDU 4523
  • 原文地址:https://www.cnblogs.com/yanglanlan/p/11134031.html
Copyright © 2011-2022 走看看