java面向对象编程(1)

package test;


import java.util.Scanner;


public class Check a number {
@SuppressWarnings("resource")
public static void main(String[] args){ 
System.out.println("Enter an inteager:");
Scanner in = new Scanner(System.in);
int c = in.nextInt();
if (c%5!=0&&c%6!=0) {
System.out.printf("%s is not divisible by either 5 or 6\n",c);
}else if ((c%5==0&&c%6!=0)||(c%5!=0&&c%6==0)) {
System.out.printf("%s is divisible by 5 or 6, but not both",c);
}else if (c%5==0&&c%6==0) {
System.out.printf("%s is divisible by both 5 and 6",c);
} 
}
}





package test;


import java.util.Scanner;


public class Compute the volume of a cylinder {
@SuppressWarnings("resource")
public static void main(String args[]){


System.out.println("Enter the radius and length of a cylinder:");
Scanner scan = new Scanner(System.in);
double radius = scan.nextDouble();
double length = scan.nextDouble();
double area = 0;
double volume = 0;
area = radius*radius*Math.PI;
volume = area*length*2+2*Math.PI*radius;
System.out.printf("The area is %f\n",area);
System.out.printf("THe volume is %f\n",volume);
}
}




package test;
import java.util.Scanner;
public class Find future dates {
@SuppressWarnings("resource")
public static void main(String[] args){ 
System.out.println("Enter today's day:");
System.out.println("Enter the number of days elapsed since today:");
Scanner in = new Scanner(System.in);
int c = in.nextInt();
int d = in.nextInt();

int m = 0;
System.out.print("Today is ");
if (c==1) {
System.out.print("Monday");
}else if (c==2) {
System.out.print("Tuesday");
}else if (c==3) {
System.out.print("Webnesday");
}
else if (c==4) {
System.out.print("Thursday");
}
else if (c==5) {
System.out.print("Friday");
}
else if (c==6) {
System.out.print("Saturday");
}else if (c==7) {
System.out.print("Sunday");
}


if (d%7==0) {
m=c;
}else if (d%7==1) {
m=c+1;
}else if (d%7==2) {
m=c+2;
}else if (d%7==3) {
m=c+3;
}else if (d%7==4) {
m=c+4;
}else if (d%7==5) {
m=c+5;
}else if (d%7==6) {
m=c+6;
}

System.out.print(" and the future day is ");
if (m==1) {
System.out.println("Monday");
}else if (m==2) {
System.out.println("Tuesday");
}else if (m==3) {
System.out.println("Wednesday");
}else if (m==4) {
System.out.println("Thursday");
}else if (m==5) {
System.out.println("Friday");
}else if (m==6) {
System.out.println("Saturday");
}else if (m==7) {
System.out.println("Sunday");
}
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值