PTA JAVA编程题汇总(一)

日期加减

import java.text.SimpleDateFormat;
import java.util.*;
public class Main  {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
         Calendar date = Calendar.getInstance();
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
          long l = in.nextLong();
         Long i = in.nextLong();
         date.setTimeInMillis(l);
        long n=i*24*60*60*1000+l;
        Date date2 = new Date(n); 
        System.out.println(format.format(date.getTime()));
          System.out.println(format.format(date2));
	}
}


声明图书类

#include<stdio.h>
#include<stdlib.h>
#define MAX 100
typedef struct NodeType
{
int id;
int password;
struct NodeType *next;
} NodeType;
int m = 0 ;
void CreaList(NodeType **, int);
NodeType *GetNode(int,int);
void PrntList(NodeType *);
int IsEmptyList(NodeType *);
void JosephusOperate(NodeType **,int);
int main(void){
int n = 0 ;

NodeType *pHead = NULL;
scanf("%d",&n);
scanf("%d",&m);
CreaList(&pHead,n);
JosephusOperate(&pHead,m);
return 1;
}
void CreaList(NodeType **ppHead,int n)
{
int i = 0;
int iPassword = 0;
NodeType *pNew = NULL;
NodeType *pCur = NULL;
for(i =1;i<= n;i++){
iPassword = m;
pNew = GetNode(i,iPassword);
if(*ppHead == NULL)
{
*ppHead = pCur = pNew;
pCur->next = *ppHead;
}
else
{
pNew->next = pCur->next;
pCur->next = pNew;
pCur = pNew;
}
}
}
NodeType *GetNode(int iId, int iPassword)
{
NodeType *pNew = NULL;
pNew = (NodeType *)malloc(sizeof(NodeType));
pNew->id = iId;
pNew->password = iPassword;
pNew->next = NULL;
return pNew;
}
void JosephusOperate(NodeType **ppHead,int iPassword)
{
int iCounter = 0;
int iFlag = 1;
NodeType *pPrv = NULL;
NodeType *pCur = NULL;
NodeType *pDel = NULL;
pPrv = pCur = *ppHead;
while(pPrv->next != *ppHead)
pPrv = pPrv->next;
while(iFlag){
for(iCounter =1 ;iCounter <iPassword;iCounter++)
{
pPrv=pCur;
pCur=pCur->next;
}
if(pPrv ==pCur) iFlag = 0;
pDel = pCur;
pPrv->next = pCur->next;
pCur = pCur->next;
iPassword = pDel->password;
printf("%d ",pDel->id);
free(pDel);
}
*ppHead = NULL;
}


三边,求解三角形的面积

import java.util.Scanner;
public Main 三角形面积 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// TODO Auto-generated method stub
System.out.print("Enter three bians: ");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
if(a + b > c && a + c > b && b + c > a && a > 0 && b > 0 && c > 0){
double S = (a+b+c)/2.0;
double P = Math.sqrt(S*(S-a)*(S-b)*(S-c));
System.out.printf("The area is:%.3f\n",P);

    }
else
      System.out.println("It can not be created a triangle");
   }
}

学生类-构造函数

import java.util.Scanner;


public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in 


);
        Student student = new Student(scanner.next(), scanner.nextInt(), scanner.next());
        System.out.println(student);
    }
}
class Student {
    private String name;
    private String sex;
    private
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值