编程尚未成功,同志仍需努力!
2015-09-13 21:51
281 查看
半月的编程学习过程,感觉自己真的喜欢上了它,看到自己的简易小程序能成功运行出来,感觉还是不错的!!
import java.util.Random;
import java.util.Scanner;
public class Lottery {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random ran = new Random();
//购买的彩票号码
System.out.println("——————————————购买彩票——————————————");
System.out.println("请输入您的身份证号:");
String str1 = sc.next();
System.out.println("请输入你购买的号码:");
String str = sc.next();
String[] lis = new String[7];
lis = str.split(",");
if(str1.length()==18){
System.out.println("您的证件号码为:");
System.out.println(str1);
}else{
System.out.println("您输入的证件号码有误!请重输入!");
}
System.out.println("你购买的彩票号为:"+str);
//彩票随机数
String[] lis1 = new String[7];
for(int i=0; i<lis1.length; i++){
lis1[i] = (ran.nextInt(35)+1)+"";
for(int j=0; j<i; j++){
if(lis1[i].equals(lis1[j])){
lis1[i] = (ran.nextInt(35)+1)+"";
j=0;
}
}
}
System.out.print("\t开奖号码为:");
for(int i=0; i<lis1.length; i++){
System.out.print(lis1[i]+",");
}
System.out.println();
//开奖
System.out.println("(开奖全解:全中奖金1000000;中6位奖金100000;中5位10000;中4位奖金:1000;中三位奖金100;中两位奖金10;中一位奖金1)");
int count = 0;
for(int i=0; i<lis.length; i++){
for(int j=0; j<lis1.length; j++){
if(lis[i].equals(lis1[j])){
count++;
}
}
}
switch(count){
case 6+1:
System.out.println("恭喜您 奖金1000000!!");break;
case 6:
System.out.println("恭喜您 奖金100000!");break;
case 5:
System.out.println("恭喜您 奖金10000!");break;
case 4:
System.out.println("恭喜您 奖金1000!");break;
case 3:
System.out.println("恭喜您 奖金100!");break;
case 2:
System.out.println("恭喜您 奖金10!");break;
case 1:
System.out.println("恭喜您 奖金1!");break;
default :
System.out.println("这么大的中奖几率都没中真丢人!!O(∩_∩)O哈哈~");
}
}
}
import java.util.Random;
import java.util.Scanner;
public class Lottery {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random ran = new Random();
//购买的彩票号码
System.out.println("——————————————购买彩票——————————————");
System.out.println("请输入您的身份证号:");
String str1 = sc.next();
System.out.println("请输入你购买的号码:");
String str = sc.next();
String[] lis = new String[7];
lis = str.split(",");
if(str1.length()==18){
System.out.println("您的证件号码为:");
System.out.println(str1);
}else{
System.out.println("您输入的证件号码有误!请重输入!");
}
System.out.println("你购买的彩票号为:"+str);
//彩票随机数
String[] lis1 = new String[7];
for(int i=0; i<lis1.length; i++){
lis1[i] = (ran.nextInt(35)+1)+"";
for(int j=0; j<i; j++){
if(lis1[i].equals(lis1[j])){
lis1[i] = (ran.nextInt(35)+1)+"";
j=0;
}
}
}
System.out.print("\t开奖号码为:");
for(int i=0; i<lis1.length; i++){
System.out.print(lis1[i]+",");
}
System.out.println();
//开奖
System.out.println("(开奖全解:全中奖金1000000;中6位奖金100000;中5位10000;中4位奖金:1000;中三位奖金100;中两位奖金10;中一位奖金1)");
int count = 0;
for(int i=0; i<lis.length; i++){
for(int j=0; j<lis1.length; j++){
if(lis[i].equals(lis1[j])){
count++;
}
}
}
switch(count){
case 6+1:
System.out.println("恭喜您 奖金1000000!!");break;
case 6:
System.out.println("恭喜您 奖金100000!");break;
case 5:
System.out.println("恭喜您 奖金10000!");break;
case 4:
System.out.println("恭喜您 奖金1000!");break;
case 3:
System.out.println("恭喜您 奖金100!");break;
case 2:
System.out.println("恭喜您 奖金10!");break;
case 1:
System.out.println("恭喜您 奖金1!");break;
default :
System.out.println("这么大的中奖几率都没中真丢人!!O(∩_∩)O哈哈~");
}
}
}
相关文章推荐
- 深入理解C语言类型转换
- C++模板
- 【springmvc+mybatis项目实战】杰信商贸-12.重点知识回顾
- c++11——move/forward
- 【LeetCode从零单刷】Convert Sorted Array to Binary Search Tree
- c#配置文件的简单操作
- python基础练习之简单用户消费卡管理(非完整版)
- Eclipse下搭建Maven框架
- Java学习笔记---设计模式之抽象工厂模式
- c++字符串操作函数
- zookeeper异常ConnectionLossException的解决办法
- Python进阶05 循环设计
- 在myeclipse中导入图片
- 对Java中类的定义,继承等的自我理解
- C++基础知识总结--指针
- C++ STL中的关于堆的函数
- php向数据库中插入中文乱码问题
- 实现C++实用的时间库
- STM32F4——RTC实时时钟
- 【LeetCode从零单刷】Single Number III