每天加点油(42)

  1. 根据输入的日期,计算是这一年的第几天。。

详细描述:

输入某年某月某日,判断这一天是这一年的第几天?。

接口设计及说明:

/*****************************************************************************
Description : 数据转换
Input Param : year 输入年份
Month 输入月份
Day 输入天

Output Param :
Return Value : 成功返回0,失败返回-1(如:数据错误)
***************************************************************************/
public static int iConverDateToDay(int year, int month, int day)
{
/
在这里实现功能,将结果填入输入数组中
/
return 0;
}

/*****************************************************************************
Description :
Input Param :

Output Param :
Return Value : 成功:返回outDay输出计算后的第几天;
失败:返回-1
*****************************************************************************/
public static int getOutDay()
{
return 0;
}

输入描述:
输入三行,分别是年,月,日

输出描述:
成功:返回outDay输出计算后的第几天;
失败:返回-1

示例1
输入
2012
12
31
输出
366

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in) ;
        while(sc.hasNext()){
            int year = sc.nextInt() ;
            int month = sc.nextInt() ;
            int day = sc.nextInt() ;
            int Day = outDay(year, month, day) ;
            System.out.println(Day);
        }
        sc.close();
 
    }
 
    private static int outDay(int year, int month, int day) {
        int [] Day = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} ;
        if(year <= 0 ||month <= 0 || month > 12 || day<= 0 || day > Day[month - 1])
            return -1;
        if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
            Day[1] = 29 ;
        }
         
        int sum = 0 ;
        for(int i = 0 ; i < month - 1 ; i ++){
            sum += Day[i] ;
        }
        return sum + day;
    }
 
}

1、对输入的字符串进行加解密,并输出。

2加密方法为:

当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;

当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;

其他字符不做变化。

3、解密方法为加密的逆过程。

接口描述:

实现接口,每个接口实现1个基本操作:

void Encrypt (char aucPassword[], char aucResult[]):在该函数中实现字符串加密并输出

说明:

1、字符串以\0结尾。

2、字符串最长100个字符。

int unEncrypt (char result[], char password[]):在该函数中实现字符串解密并输出

说明:

1、字符串以\0结尾。

2、字符串最长100个字符。

输入描述:
输入说明
输入一串要加密的密码
输入一串加过密的密码

输出描述:
输出说明
输出加密后的字符
输出解密后的字符

示例1
输入
abcdefg
BCDEFGH
输出
BCDEFGH
abcdefg

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s1 = sc.nextLine();
            String s2 = sc.nextLine();
            char[] ch1 = s1.toCharArray();
            char[] ch2 = s2.toCharArray();
            for(int i=0; i<ch1.length; i++) {
                if(ch1[i]>='A' && ch1[i]<'Z') {
                    ch1[i] = (char)(ch1[i]+33);
                }else if(ch1[i] == 'Z') {
                    ch1[i] = 'a';
                }else if(ch1[i]>='a' && ch1[i]<'z') {
                    ch1[i] = (char)(ch1[i]-31);
                }else if(ch1[i] == 'z') {
                    ch1[i] = 'A';
                }else if(ch1[i]>='0' && ch1[i]<'9') {
                    ch1[i] = (char)(ch1[i]+1);
                }else if(ch1[i] == '9') {
                    ch1[i] = '0';
                }
            }
            for(int i=0; i<ch2.length; i++) {
                if(ch2[i]>'A' && ch2[i]<='Z') {
                    ch2[i] = (char)(ch2[i]+31);
                }else if(ch2[i] == 'A') {
                    ch2[i] = 'z';
                }else if(ch2[i]>'a' && ch2[i]<='z') {
                    ch2[i] = (char)(ch2[i]-33);
                }else if(ch2[i] == 'a') {
                    ch2[i] = 'Z';
                }else if(ch2[i]>'0' && ch2[i]<='9') {
                    ch2[i] = (char)(ch2[i]-1);
                }else if(ch2[i] == '0') {
                    ch2[i] = '9';
                }
            }
            String jiami = String.copyValueOf(ch1);
            String jiemi = String.copyValueOf(ch2);
            System.out.println(jiami);
            System.out.println(jiemi);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值