PAT 数字分类

本博客介绍了一个使用Java编写的程序,该程序能够处理用户输入的多个整数,进行复杂的条件判断和数学运算,包括求偶数且能被5整除的数之和、基于除以5余数的不同运算、求特定条件下平均值等,并以特定格式输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package test;

 

import java.text.DecimalFormat;

import java.util.Scanner;

public class MainA {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int num=sc.nextInt();

int[] aa=new int[num];

int A1 = 0,A2=0,A3=0,A5=0,bb=0,cc=0,dd=0,sum=0;

int A4=0;

for (int i = 0; i < num; i++) {

aa[i]=sc.nextInt();

}

for (int i = 0; i < aa.length; i++) {

if(aa[i]%5==0&&aa[i]%2==0) 

A1=A1+aa[i];

else if(aa[i]%5==1) {

dd++;

if(dd%2!=0) {

A2=A2+aa[i];

}else {

A2=A2-aa[i];

}

}

else if(aa[i]%5==2)

A3++;

else if(aa[i]%5==3) {

bb++;

sum=sum+aa[i];

A4=sum;

}

else if(aa[i]%5==4) {

if(aa[i]>A5) {

A5=aa[i];

}

}

}

if(A1!=0) {

System.out.print(A1+" ");

}else

System.out.print("N"+" ");

if(A2!=0) {

System.out.print(A2+" ");

}else

System.out.print("N"+" ");

if(A3!=0) {

System.out.print(A3+" ");

}else

System.out.print("N"+" ");

if(A4!=0) {

System.out.print(new DecimalFormat("#.0").format((float)A4/bb)+" ");

}else

System.out.print("N"+" ");

if(A5!=0) {

System.out.print(A5);

}else

System.out.println("N");

}

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值