编程算法基础-数字数码管-隐藏密码
作业
数字数码管
数字或字母可以用7位数码管显示(就是排列为8字形的7个数码管)
@@@@ 0
@ @ 1 2
@ @ 3
@@@@ 4 5
@ @ 6
@ @
@@@@
对于大型灯管,为了节约使用,在切换数字的时候,如果该灯管的状态没有改变,则不需要对该灯管关了再开。
已知一个数字变化的系列,求7个数码管开关的动作。
3:0,2,3,5,6
6:0,1,4,6,5,3
下面的代码仅仅是两个数字变化后,第几个灯管变化,题目要求数字变化系列。
还有一个逻辑问题:全灭到第一个数没有实现亮灯号。
import java.util.Arrays;
import java.util.Scanner;/*数字数码管数字或字母可以用7位数码管显示(就是排列为8字形的7个数码管)@@@@ 0@ @ 1 2@ @ 3@@@@ 4 5@ @ 6@ @@@@@对于大型灯管,为了节约使用,在切换数字的时候,如果该灯管的状态没有改变,则不需要对该灯管关了再开。
已知一个数字变化的系列,求7个数码管开关的动作。3:0,2,3,5,6
6:0,1,4,6,5,3
*/
public class NumberLight {public static void main(String[] args) {System.out.println("First Number:");Scanner sc = new Scanner(System.in);int first = sc.nextInt();System.out.println("Second Number:");int second = sc.nextInt();System.out.print("要反向的开关号为:");for(int i=0;i<7;i++){if(showNumber(second)[i]!=showNumber(first)[i]){//判断这两个数之间那几个位置不同System.out.print(i+" ");//打印出不同的地方}}System.out.println();System.out.println(Arrays.toString(showNumber(first)));System.out.println(Arrays.toString(showNumber(second)));}//数字数码管显示方法,参数为要显示的数字public static int[] showNumber(int a){int []n = {0,0,0,0,0,0,0};switch (a) {case 0:n[0]=1;n[1]=1;n[2]=1;n[4]=1;n[5]=1;n[6]=1;break;case 1:n[2]=1;n[5]=1;break;case 2:n[0]=1;n[2]=1;n[3]=1;n[4]=1;n[6]=1;break;case 3:n[0]=1;n[2]=1;n[3]=1;n[5]=1;n[6]=1;break;case 4:n[1]=1;n[2]=1;n[3]=1;n[5]=1;break;case 5:n[0]=1;n[1]=1;n[3]=1;n[5]=1;n[6]=1;break;case 6:n[0]=1;n[1]=1;n[3]=1;n[4]=1;n[5]=1;n[6]=1;break;case 7:n[0]=1;n[2]=1;n[5]=1;break;case 8:n[0]=1;n[1]=1;n[2]=1;n[3]=1;n[4]=1;n[5]=1;n[6]=1;break;case 9:n[0]=1;n[1]=1;n[2]=1;n[3]=1;n[5]=1;n[6]=1;break;default:break;}return n;//返回int数组}}
First Number:
3
Second Number:
8
要反向的开关号为:1 4
[1, 0, 1, 1, 0, 1, 1]
[1, 1, 1, 1, 1, 1, 1]
改进版,实现连续数字序列
package Homework;import java.util.Scanner;/*数字数码管数字或字母可以用7位数码管显示(就是排列为8字形的7个数码管)@@@@ 0@ @ 1 2@ @ 3@@@@ 4 5@ @ 6@ @@@@@对于大型灯管,为了节约使用,在切换数字的时候,如果该灯管的状态没有改变,则不需要对该灯管关了再开。
已知一个数字变化的系列,求7个数码管开关的动作。3:0,2,3,5,6
6:0,1,4,6,5,3
*/
public class NumberLight {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入数字序列(用逗号分隔):");String str = sc.nextLine();str="-1,"+str;//一刀切上式,给初始补一个-1,在后面调用方法的时候进入switch的default,默认是全灭的。这里只要写不是0到9的数字即可。String str2 [] = str.split(",");//被分隔后的字符串数组System.out.println("变更数字时要反向的开关号为:");//外层循环,对str2循环,比较后一个与前一个的区别//内层循环,对每一个数字里面的数码管号循环,判断是否有不同。for(int i=0;i
请输入数字序列(用逗号分隔):
8,0,0
变更数字时要反向的开关号为:
8:0 1 2 3 4 5 6
0:3
0:
隐藏密码
密码备忘扰乱法
我们的密码如果很长很复杂,容易忘记。如果太简单,不安全。把密码记录在本子上,更容易泄密!
有人想了这么个办法,把密码嵌入一堆随机的数字中。
因为每个人对密码完全记住困难,但从一些线索中回忆出来就很容易。
密码:75383
3 5 6 4 7 2 8 6
5 4 7 2 7 0 7 4
1 6 5 9 5 8 0 3
1 6 7 0 3 6 8 9
3 6 4 7 8 0 9 4
3 4 6 9 3 6 8 9
2 1 3 6 7 8 1 3
2 7 3 9 4 6 3 5
嵌入时,可以横向或纵向。如果再复杂点,可以设计对角线。
/** 隐藏密码密码备忘扰乱法
我们的密码如果很长很复杂,容易忘记。如果太简单,不安全。把密码记录在本子上,更容易泄密!
有人想了这么个办法,把密码嵌入一堆随机的数字中。
因为每个人对密码完全记住困难,但从一些线索中回忆出来就很容易。
密码:753833 5 6 4 7 2 8 6
5 4 7 2 7 0 7 4
1 6 5 9 5 8 0 3
1 6 7 0 3 6 8 9
3 6 4 7 8 0 9 4
3 4 6 9 3 6 8 9
2 1 3 6 7 8 1 3
2 7 3 9 4 6 3 5嵌入时,可以横向或纵向。如果再复杂点,可以设计对角线。
*/package Homework;import java.util.Scanner;public class HideCode {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入要隐藏的密码:");String code = sc.nextLine();System.out.println("请输入矩阵宽:");int width = sc.nextInt();System.out.println("请输入矩阵高:");int height = sc.nextInt();Scanner sc2 = new Scanner(System.in);System.out.println("请输入方向(1表示横,2表示竖,3表示斜):");String orientation = sc2.nextLine();System.out.println("请输入起始位置x坐标:");int x = sc2.nextInt();System.out.println("请输入起始位置y坐标:");int y = sc2.nextInt();//首先生成一个随机矩阵int[][]a = new int[height][width];for(int i=0;iwidth||y+code.length()-1>height){errorTips();}else{for(int i=0;iwidth||y>height){errorTips();}else{for(int i=0;iwidth||y+code.length()-1>height){errorTips();}else{for(int i=0;i
请输入要隐藏的密码:
1234567890
请输入矩阵宽:
11
请输入矩阵高:
11
请输入方向(1表示横,2表示竖,3表示斜):
3
请输入起始位置x坐标:
1
请输入起始位置y坐标:
2
2 1 4 0 1 8 3 9 3 2 9
1 7 2 9 2 6 4 0 3 0 5
6 7 7 3 2 5 1 6 7 9 8
1 0 7 7 4 4 9 0 8 4 8
2 4 3 4 4 5 2 5 1 5 5
9 6 5 8 0 2 6 9 7 8 2
1 8 9 6 3 4 7 7 2 4 5
4 6 4 2 0 8 6 3 8 4 4
8 1 2 6 7 8 0 6 6 9 8
3 1 0 6 4 5 3 7 9 0 0
3 6 7 1 3 1 9 3 3 0 3
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
