#include<reg51.h>
sbit beep=P2^3
sbit dula=P2^6
sbit wela=P2^7
unsigned char i=100
unsigned char j,k,temp,key
void delay(unsigned char i)
{
for(j=ij>0j--)
for(k=125k>0k--)
}
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}
display(unsigned char num)
{
P0=table[num]
//P0=0xff
dula=1
dula=0
P0=0xc0
wela=1
wela=0
}
void main()
{
dula=0
wela=0
while(1)
{
P3=0xfe
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xee:
key=0
break
case 0xde:
key=1
break
case 0xbe:
key=2
break
case 0x7e:
key=3
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
display(key)
// P0=table[key]
/*P0=0xff
dula=1
while(i--)
dula=0
P0=0xc0
wela=1
wela=0
dula=0
wela=0
P0=0xff
dula=1
dula=0
P0=0xc5
wela=1
wela=0*/
P1=0xfe
}
}
P3=0xfd
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xed:
key=4
break
case 0xdd:
key=5
break
case 0xbd:
key=6
break
case 0x7d:
key=7
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
display(key)
/* P0=table[key]
dula=1
// while(100--)
dula=0
P0=0xc0
wela=1
wela=0
*/ P1=0xfc
}
}
P3=0xfb
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xeb:
key=8
break
case 0xdb:
key=9
break
case 0xbb:
key=10
break
case 0x7b:
key=11
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
display(key)
/*P0=table[key]
dula=1
// while(100--)
dula=0
P0=0xc0
wela=1
wela=0
*/ P1=0xf8
}
}
P3=0xf7
temp=P3
temp=temp&0xf0
if(temp!=0xf0)
{
delay(10)
if(temp!=0xf0)
{
temp=P3
switch(temp)
{
case 0xe7:
key=12
break
case 0xd7:
key=13
break
case 0xb7:
key=14
break
case 0x77:
key=15
break
}
while(temp!=0xf0)
{
temp=P3
temp=temp&0xf0
beep=0
}
beep=1
display(key)
/* P0=table[key]
dula=1
// while(100--)
dula=0
P0=0xc0
wela=1
wela=0
*/ P1=0xf0
}
}
}
}
public class JuZhen {public static void main(String[] args) {
int[][] ary = new int[4][4]
for (int i = 0 i < ary.length i++) {
for (int j = 0 j < ary[i].length j++) {
ary[i][j] = (int) (Math.random() * 2)//随机填充0或者1
System.out.print(ary[i][j] + "\t")
}
System.out.println()
}
int maxR = 0//保存行出现1的次数的最大值,
int maxC = 0//保存列出现1的次数的最大值,
int row = 0//行
int col = 0//列
for (int i = 0 i < ary.length i++) {
int numR = 0//每次循环一行的1的次数统计
int numC = 0//每次循环一列的1的次数统计
for (int j = 0 j < ary[i].length j++) 拦世{
if (ary[i][j] == 1) {
numR++//次数加1
歼判 }
氏衡改 if (ary[j][i] == 1) {
numC++
}
}
if (numR > maxR) {//行的和行的进行比较
maxR = numR
row = i
}
if (numC > maxC) {
maxC = numC
col = i
}
}
System.out.println("【行数从1开始】 最多数字1的行:" + (row + 1))
System.out.println("【列数从1开始】 最多数字1的列:" + (col + 1)) }
}
输出
0 1 1 10 1 0 1
1 1 0 0
1 0 1 1
【行数从1开始】 最多数字1的行:1
【列数从1开始】 最多数字1的列:2
import java.util.ArrayList
import java.util.List
import java.util.Scanner
public class M {
public static void main(String[] args) {
int[][] m = new int[4][4]
System.out.println("请输入4*4方阵(要求四行四列):")
Scanner scanner = new Scanner(System.in)
for (int i = 0i <4i++) {
for (int j = 0j <亩旁 4j++) {
m[j][i] = scanner.nextInt()
}
}
int T1 = 0, T2 = 0, T3 = 1, T4 = m[0][0]
List<Integer>X = new ArrayList<>()
List<Integer>Y = new ArrayList<>()
for (int y = 0y <4y++) {
for (int x = 0x <4x++) {
if (x == y || x + y == 3) {
T1 += m[x][y]
if (x % 2 == 0 &&y % 2 == 0) {
T3 *= m[x][y]
}
if (m[x][y] >T4) {
X.clear()
X.add(x)
Y.clear()
Y.add(y)
T4 = m[x][y]
} else if (m[x][y] == T4) {
X.add(x)
Y.add(y)
}
}
if (x == 0 || x == 3 || y == 0 || y == 3) {
T2 += m[x][y]
}
}
}
System.out.println("对角稿敬线上各元素的和为:" + T1)
System.out.println("周边元素的和为:" + T2)
System.out.println("对角线上行、列下标均为偶数的各元素的积为:" + T3)
System.out.println("对角线上其值最大的元素为:" + T4 + ",其对应的位置有:")
for (int i = 0i <X.size()i++) {
System.out.println("位于第" + Y.get(i) + "行,第" + X.get(i) + "列"键耐慎)
}
System.out.println("\n提示:该方阵从0行0列起3行3列终")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)