第三周作业-循环与判断语句
2014-04-19 13:47
316 查看
类名:MathDemo
类名:CalculatePi
类名:LeapYear
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args){
//Creat a Scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter a year:");
int year = input.nextInt();
//Check if the year is a leap year
boolean isLeapYear=(year % 4 ==0 && year % 100 !=0) || (year % 400 == 0);
//Display the result
System.out.println(year + "is a leap year?" + isLeapYear);
}
}
public class MathDemo { public static void main(String[] args){ System.out.println("abs(-5)="+Math.abs(-5)); System.out.println("max(6.75,3.14)="+Math.max(6.75,3.14)); System.out.println("min(100,200)="+Math.min(100,200 )); System.out.println("round(3.5)="+Math.round(3.5)); System.out.println("round(-6.5)="+Math.round(-6.5)); System.out.println("sqrt(2)="+Math.sqrt(2)); System.out.println("pow(2,5)="+Math.pow(2,5)); System.out.println("E="+Math.E); System.out.println("exp(2)="+Math.exp(2)); System.out.println("log(2)="+Math.log(2)); System.out.println("ceil(6.75)="+(int)Math.ceil(6.75)); System.out.println("floor(6.75)="+(int)Math.floor(6.75)); System.out.println("Pi="+Math.PI); System.out.println("sin(Pi/4)="+Math.sin(Math.PI/4)); System.out.println("cos(1)="+Math.cos(1)); } }
public class LoopExample { public static void main(String[] args) { int lay=4; for(int i=1;i<=lay;i++) { for(int k=1;k<=lay-i;k++) { System.out.print(" "); } for(int j=1;j<=2*i-1;j++) { System.out.print("*"); } System.out.println( ); } } }
类名:CalculatePi
public class CalculateP { public static void main(String args[]){ double sum = 0.0; for(int i = 1; i <= 70000000; i +=4){ sum += (1.0/i - 1.0/(i+2)); } double pi = 4*sum; System.out.println("pi="+pi); } }
类名:LeapYear
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args){
//Creat a Scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter a year:");
int year = input.nextInt();
//Check if the year is a leap year
boolean isLeapYear=(year % 4 ==0 && year % 100 !=0) || (year % 400 == 0);
//Display the result
System.out.println(year + "is a leap year?" + isLeapYear);
}
}
相关文章推荐
- I have a dream
- PSD -> HTML & CSS (已放在新浪云端
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro
- Baskets of Gold Coins 2401
- 微软面试100题之29题:栈的push、pop 序列
- 纯CSS实现多选组件 checkbox
- android 完全退出应用程序(经过严格验证)
- C++使用POST方法向网页提交数据-----C++发送HTTP数据获取Google天气预报
- velocity学习记录之一(velocity基本概念)
- 面向对象语言做项目的步骤
- vlc-2.1.3编译 (未完成)
- Ubuntu Linux 永久挂载(mount)分区
- ADO 应用程序不能在运行级别较低的操作系统上运行的解决方案
- POJ题目分类【实在是不知道哪个是原创了】
- 【C#历程】Upper in CH
- c++动态的创建对象数组
- 软件安全加解密,产品授权控制/防盗版Zend Guard™控件
- Qt获取网页源码
- nasm程序从32位到64位平台的移植(二)
- 用unity3d实现简单的主服务器连接