java面向对象编程(1)

来源:互联网 发布:dnf补丁制作软件 编辑:程序博客网 时间:2024/06/06 07:10

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");}}}