以下答案都是自己做的答案,可能会有错误的地方。如果核对的时候有发现有误的,请指导我改正一下!!
1.1(显示三条消息)
package demo11;
public class demo01 {
public static void main(String[] args){
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
}
}
.1.2(显示五条信息)
package demo11;
public class demo02 {
public static void main(String[] args){
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
System.out.println("Welcome to Java");
}
}
1.3(显示图案)
package demo11;
public class demo03 {
public static void main(String[] args){
System.out.println(" J A V V A ");
System.out.println(" J A A V V A A");
System.out.println("J J AAAAA V V AAAAA");
System.out.println(" JJ A A V A A");
}
}
1.4(打印表格)
package demo11;
public class demo04 {
public static void main(String[] args){
System.out.println("a a^2 a^3");
System.out.println("1 1 1");
System.out.println("2 4 8");
System.out.println("3 9 27");
System.out.println("4 16 64");
}
}
1.5(计算表达式)
package demo11;
public class demo05 {
public static void main(String[] args){
double a=(9.5*4.5-2.5*3)/(45.5-3.5);
System.out.println(a);
}
}
1.6(数列求和)
package demo11;
public class demo06 {
public static void main(String[] args){
int sum=0;
for(int i=1;i<=9;i++){
sum+=i;
}
System.out.println(sum);
}
}
1.7(近似求P)
package demo11;
public class demo07 {
public static void main(String[] args){
double a=4*(1-(1.0/3)+(1.0/5)-(1.0/7)+(1.0/9)-(1.0/11));
double b=4*(1-(1.0/3)+(1.0/5)-(1.0/7)+(1.0/9)-(1.0/11)+(1.0/13));
System.out.println(a);
System.out.println(b);
}
}
1.8(圆的面积和周长)
package demo11;
public class demo08 {
public static void main(String[] args){
double radius=5.5;
double perimeter =2*radius*Math.PI;
double area=radius* radius*Math.PI;
System.out.println("该圆的周长为:"+perimeter+",面积为:"+area);
}
}
1.9(矩形的面积和周长)
package demo11;
public class demo09 {
public static void main(String[] args){
double width=4.5;
double height=7.9;
double area=width*height;
System.out.println(area);
}
}
1.10(以英里计的平均速度)
package demo11;
public class demo10 {
public static void main(String[] args){
int time=45*60+30;
double distance=14;
System.out.println("每英里速度为:"+(distance/time)*60/1.6+"");
}
}
1.11(人口估算)
package demo11;
public class demo11 {
public static void main(String[] args){
int mCurrentPeoPle=312032486;
final int ALL_OF_TIME=5*365*24*60*60;
//出生人口
int mBirthPeople=ALL_OF_TIME/7;
//死亡人口
int mDeathPeople=ALL_OF_TIME/13;
//移民人口
int mMigrate=ALL_OF_TIME/45;
int mAllPeople=(mCurrentPeoPle+mBirthPeople+mMigrate)-mDeathPeople;
System.out.println(mAllPeople+",五年共生长了"+(mAllPeople-mCurrentPeoPle)+",人口");
}
}
1.12(以公里计的平均速度)
package demo11;
public class demo12 {
public static void main(String[] args){
int time=100*60+35;
double distance=24;
System.out.println("每公里速度为:"+(distance/time)*60*1.6);
}
}
1.13(代数:求解2X2线性方程)
package demo11;
public class demo13 {
public static void main(String[] args){
double a=3.4;
double b=50.2;
double c=2.1;
double d=0.55;
double e=44.5;
double f=5.9;
int x=(int)((e*d-b*f)*100/(a*d-b*c));
int y=(int)((a*f-e*c)*100/(a*d-b*c));
System.out.println("3.4x+50.2y=44.5\n2.1x+0.55y=5.9\n方程解是:\n"
+ "x:"+x/100.00+",y="+y/100.00);
}
}