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 }
  • 相关阅读:
    C++指针
    Linux Ubuntu常用终端命令
    java-JDBC-Oracle数据库连接
    HDU 1890 区间反转
    Hdu-3487 Splay树,删除,添加,Lazy延迟标记操作
    UVa 10088
    UVa10025-The ? 1 ? 2 ? ... ? n = k problem
    UVa10023手动开大数平方算法
    UVa 10007
    点的双联通+二分图的判定(poj2942)
  • 原文地址:https://www.cnblogs.com/yanglanlan/p/11134031.html
Copyright © 2011-2022 走看看