java语言

Java语言程序设计基础篇

时间:2022-11-30 06:23:42 java语言 我要投稿
  • 相关推荐

Java语言程序设计基础篇

  导语:Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。下面我们来看看Java语言程序设计基础篇,希望对大家有所帮助。

  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 2.1x+0.55y=5.9 方程解是: "

  + "x:"+x/100.00+",y="+y/100.00);

  }

  }


【Java语言程序设计基础篇】相关文章:

Java语言编程基础知识04-18

java语言程序设计实验报告10篇12-08

Java基础知识精选02-20

Java基础知识点12-26

Java语言的内部类12-13

Java语言的编程特点03-18

Java语言有什么特点08-03

Java语言的优点有哪些04-15

Java语言的5大特点08-27

C语言基础知识12-20