小编会慢慢补上去,敬请期待

近似求π(输出语句,加减乘除运算)

public class Test {public static void main(String[] args){double pi1=4*(1.0-1/3+1/5-1/7+1/9-1/11);double pi2=4*(1.0-1/3+1/5-1/7+1/9-1/11+1/13);System.out.println(pi1);System.out.println(pi2);//方法二System.out.println(Math.PI);}
}

打印表格(输出语句,字符串)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入层数:");double r = sc.nextDouble();for(int i =1;i<=r;i++){System.out.println(i+"\t"+Math.pow(i,2)+"\t"+ Math.pow(i,3));}}
}

圆的面积和周长(输出语句,加减乘除运算)

import java.util.Scanner;public class Test {public static void main(String[] args){Scanner sc =new Scanner(System.in);System.out.println("请输入圆半径:");double r=sc.nextDouble();double perimeter=2*r*Math.PI;double area =Math.pow(r,2)*Math.PI;System.out.println("请输入圆周长:"+perimeter);System.out.println("请输入圆面积:"+area);}
}

将摄氏温度转换为华氏温度(输入输出,变量)

import java.util.Scanner;public class Test {public static void main(String[] args){Scanner sc =new Scanner(System.in);System.out.println("请输入摄氏温度:");double du=sc.nextDouble();double hua=(9.0/5)*du+32;System.out.println("华氏温度为:"+hua);}
}

计算圆柱体的体积(输入输出,变量)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入半径:");double r = sc.nextDouble();System.out.println("请输入高:");double h = sc.nextDouble();double volume = Math.PI * Math.pow(r,2) * h;System.out.println("圆柱体体积为" + volume);}
}

求一个整数各位数的和(输入输出,模运算)

递归方法:


import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入整数:");int num = sc.nextInt();System.out.println(bits(num));}public  static int bits(int num){if (num<=10){int c=num%10;return c;}else{int c=num%10;return c+bits(num/10);}}
}

循环方法:

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc =new Scanner(System.in);System.out.println("请输入一个整数");int number=sc.nextInt();int sum=0;for (int i = 0; Math.pow(10,i)<number; i++) {sum+=(number/Math.pow(10,i))%10;}System.out.println("各个位上之和为:"+sum);}
}

财务应用程序:复利值(输入输出,加减乘除运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入月份:");int month = sc.nextInt();double money=100*month*(1+0.00417);System.out.println(money);}
}

显示时间(模运算)

整钱兑零(模运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入多少美元:");double money= sc.nextDouble();num(money);}public static void num(double money){money = money*100;int dollar= (int)money/100;money=money%100;int quarter =(int)money%25;money=money%25;int dime =(int)money%10;money=money%10;int nickel =(int)money%5;System.out.println("1美元:"+dollar+"\n2角5分:"+quarter+"\n角:"+dime+"\n分:"+nickel);}}

几何:两点间距离(输入输出,Math类)

import com.sun.corba.se.spi.ior.IdentifiableFactory;import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入x1:");double x1 = sc.nextDouble();System.out.println("请输入y1:");double y1 = sc.nextDouble();System.out.println("请输入x2:");double x2 = sc.nextDouble();System.out.println("请输入y2:");double y2 = sc.nextDouble();System.out.println(distance(x1,y1,x2,y2));}public static double distance(double x1,double y1,double x2,double y2){double dis=Math.pow((x2-x1),2)-Math.pow((y2-y1),2);double de=Math.pow(dis,1/2);return de;}
}

计算身体质量指数(if语句)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入您体重(kg):");double weight= sc.nextDouble();System.out.println("请输入您身高(m):");double hight= sc.nextDouble();double bmi=Math.pow((weight/hight),2);if(bmi<18.5){System.out.println("您比较瘦,建议多吃点");}else if(bmi<25.0){System.out.println("您身体状态好,继续保持");}else if(bmi<30){System.out.println("您比较胖,建议少吃点");}else if(bmi>30.0){System.out.println("您吃的太多了,建议少吃点");}}}

判定闰年(if语句,逻辑运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入年号:");int yes= sc.nextInt();if(yes%400==0){System.out.println(yes+":这是一个闰年");}else {System.out.println(yes+":这不是一个闰年");}}}

彩票(if语句,模运算,逻辑运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个二位数:");//设置二位数随机彩票数int lottery=(int)(Math.random()*100);System.out.println("彩票:"+lottery);for (int i=0;i<3;i++){int number= sc.nextInt();System.out.println("您还有"+(2-i)+"机会哦!");if(number==lottery){System.out.println("恭喜你,获取10000美元");}else if(number%100==lottery%100 && number%10==lottery%10 && number%100==lottery%10 && number%10==lottery%100) {System.out.println("恭喜你,获取3000美元");}else if(number%100==lottery%100 || number%10==lottery%10 || number%100==lottery%10|| number%10==lottery%100) {System.out.println("恭喜你,获取1000美元");}else {System.out.println("恭喜你,什么都没有");}}}}

代数:解一元二次方程(if语句,Math类)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入a:");int a= sc.nextInt();System.out.println("请输入b:");int b= sc.nextInt();System.out.println("请输入c:");int c= sc.nextInt();double judge=Math.pow(b,2)-4*a*c;if(judge>0){double r1=((b*-1)+Math.pow(judge,0.5))/2*a;double r2=((b*-1)-Math.pow(judge,0.5))/2*a;System.out.println("有二个根: r1="+r1+" r2="+r2);}else if (judge==0){double r=((b*-1)+Math.pow(judge,0.5))/2*a;System.out.println("有一个根: r="+r);}else if (judge<0){System.out.println("没有根");}}}

代数:求解2×2线程方程(格式化输出)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入a:");double a= sc.nextDouble();System.out.println("请输入b:");double b= sc.nextDouble();System.out.println("请输入c:");double c= sc.nextDouble();System.out.println("请输入d:");double d= sc.nextDouble();System.out.println("请输入e:");double e= sc.nextDouble();System.out.println("请输入f:");double f= sc.nextDouble();double ac=a*b-b*c;if(ac != 0){double x=(e*d-b*f)/(a*d-b*c);double y=(a*f-e*c)/(a*d-b*c);System.out.println("x:"+x+"y:"+y);}else {System.out.println("方程无解");}}}

找到将来的日期(switch语句,模运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入星期几:");int day=sc.nextInt();System.out.println("请输入后面天数:");int nextday=sc.nextInt();int days=(day+nextday)%7;switch (days){case 1:System.out.println("今天星期:"+day+"过"+nextday+"天,星期一");break;case 2:System.out.println("今天星期:"+day+"过"+nextday+"天,星期二");break;case 3:System.out.println("今天星期:"+day+"过"+nextday+"天,星期三");break;case 4:System.out.println("今天星期:"+day+"过"+nextday+"天,星期四");break;case 5:System.out.println("今天星期:"+day+"过"+nextday+"天,星期五");break;case 6:System.out.println("今天星期:"+day+"过"+nextday+"天,星期六");break;case 7:System.out.println("今天星期:"+day+"过"+nextday+"天,星期天");}}}

给出一个月的总天数(switch语句)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入年份:");int yes = sc.nextInt();System.out.println("请输入月份:");int month = sc.nextInt();if (yes % 400 == 0) {switch (month) {case 1:System.out.println(yes + "年" + month + "月" + "有31天");break;case 2:System.out.println(yes + "年" + month + "月" + "有29天");break;case 3:System.out.println(yes + "年" + month + "月" + "有31天");break;case 14:System.out.println(yes + "年" + month + "月" + "有30天");break;case 5:System.out.println(yes + "年" + month + "月" + "有31天");break;case 6:System.out.println(yes + "年" + month + "月" + "有30天");break;case 7:System.out.println(yes + "年" + month + "月" + "有31天");break;case 8:System.out.println(yes + "年" + month + "月" + "有31天");break;case 9:System.out.println(yes + "年" + month + "月" + "有30天");break;case 10:System.out.println(yes + "年" + month + "月" + "有31天");break;case 11:System.out.println(yes + "年" + month + "月" + "有30天");break;case 12:System.out.println(yes + "年" + month + "月" + "有31天");}}switch (month) {case 1:System.out.println(yes + "年" + month + "月" + "有31天");break;case 2:System.out.println(yes + "年" + month + "月" + "有28天");break;case 3:System.out.println(yes + "年" + month + "月" + "有31天");break;case 14:System.out.println(yes + "年" + month + "月" + "有30天");break;case 5:System.out.println(yes + "年" + month + "月" + "有31天");break;case 6:System.out.println(yes + "年" + month + "月" + "有30天");break;case 7:System.out.println(yes + "年" + month + "月" + "有31天");break;case 8:System.out.println(yes + "年" + month + "月" + "有31天");break;case 9:System.out.println(yes + "年" + month + "月" + "有30天");break;case 10:System.out.println(yes + "年" + month + "月" + "有31天");break;case 11:System.out.println(yes + "年" + month + "月" + "有30天");break;case 12:System.out.println(yes + "年" + month + "月" + "有31天");}}
}

回文数字(if语句,模运算)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个整数:");int number = sc.nextInt();if (number<0){System.out.println("对不起,回文数没有负数");}else if(number>0 && number<10){System.out.println("回文数为:"+number);}else {int val=0;int num=number;while (val<num){val=number%10+10*val;number/=10;}if (val>num){val/=10;}System.out.println("回文数为:"+val);}}
}

几何:正多边形的面积(Math类)

import java.util.Scanner;public class Test {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个边数:");int edge=sc.nextInt();System.out.println("请输入一个边长:");double longedge = sc.nextDouble();double s=(edge*Math.pow(longedge,2))/(4*Math.tan(Math.PI/edge));System.out.println(s);}
}

java从小白开始的练习(一)相关推荐

  1. 《Java从小白到大牛》之第14章 异常处理(上)

    <Java从小白到大牛>纸质版已经上架了!!! 很多事件并非总是按照人们自己设计意愿顺利发展的,而是有能够出现这样那样的异常情况.例如:你计划周末郊游,你的计划会安排满满的,你计划可能是这 ...

  2. 《Java从小白到大牛》之第9章 字符串

    <Java从小白到大牛>纸质版已经上架了!!! 由字符组成的一串字符序列,称为"字符串",在前面的章节中也多次用到了字符串,本章将重点介绍. Java中的字符串 Jav ...

  3. 《Java从小白到大牛》之第11章 对象

    <Java从小白到大牛>纸质版已经上架了!!! 类实例化可生成对象,实例方法就是对象方法,实例变量就是对象属性.一个对象的生命周期包括三个阶段:创建.使用和销毁.前面章节已经多少用到了对象 ...

  4. java下标运算符_《Java从小白到大牛精简版》之第6章 运算符(下)

    <Java从小白到大牛>纸质版已经上架了!! 6.4 位运算符 位运算是以二进位(bit)为单位进行运算的,操作数和结果都是整型数据.位运算符有如下几个运算符:&.|.^.~.&g ...

  5. Java从小白到大牛第1篇 Java基础-关东升-专题视频课程

    Java从小白到大牛第1篇 Java基础-3042人已学习 课程介绍         本视频是智捷课堂推出的一套"Java语言学习立体教程"的视频第一部分,读者以及观看群是初级小白 ...

  6. JAVA—从小白到入门小白

    学习一个网站的全套,后来想放这个网站的链接,然后找不着了...罪恶感,实时更新,包含很多自己的理解,不严谨请海涵. 说一下我们的目标.完成SSM框架的学习,并实现天猫全栈. JAVA-从小白到入门小白 ...

  7. Java从小白到大牛第4篇项目实战视频课程2——Java版QQ-关东升-专题视频课程

    Java从小白到大牛第4篇项目实战视频课程2--Java版QQ-1778人已学习 课程介绍         本项目是Java SE技术实现的QQ2006聊天工具,所涉及到的知识点:Java面向对象.L ...

  8. Java从小白到大牛第2篇 【面向对象】-关东升-专题视频课程

    Java从小白到大牛第2篇 [面向对象]-2739人已学习 课程介绍         本视频是智捷课堂推出的一套"Java语言学习立体教程"的视频第二部分,读者以及观看群是初级小白 ...

  9. Java从小白到大牛第4篇项目实战1——PetStore宠物商店-关东升-专题视频课程

    Java从小白到大牛第4篇项目实战1--PetStore宠物商店-1764人已学习 课程介绍         PetStore是Sun(现在Oracle)公司为了演示自己的Java EE技术,而编写的 ...

  10. Java基础小白入门教程-----百知教育java基础学习1---胡鑫喆

    Java基础小白入门教程(胡大大出品,彩蛋请自寻) 胡鑫喆 https://www.bilibili.com/video/BV1wE411V7Zo?from=search&seid=38511 ...

最新文章

  1. JStorm与Storm源码分析(三)--Scheduler,调度器
  2. python开发工程师面试题-2019超实用Python开发工程师面试题分享
  3. hadoop之 参数调优
  4. win10 管理linux文件,Linux子系统文件可在未来的Win10发行版中通过资源管理器访问...
  5. Atomic Integer 原理分析-其他方法
  6. 无状态会话bean(1)---定义
  7. linux 运行ca.crt,linux下使用openssl生成 csr crt CA证书,opensslcsr
  8. Redis高可用方案哨兵机制------ 配置文件sentinel.conf详解
  9. java怎么拦截数据库查询结果_关于mybatis拦截器,有谁知道怎么对结果集进行拦截,将指定字段查询结果进行格式化...
  10. C语言之基本算法09—各位全是a的数列之和
  11. 笔刷怎么做_零基础怎么学板绘?板绘小白必备基础知识
  12. 在售后技术服务里,Kubernetes到底是什么? | 凌云时刻
  13. JS rgba颜色转16进制
  14. 为什么经转速环PI之后的输出量是电流(基于MTPA分析,内含代码)
  15. uniapp app 腾讯云 IM 通讯 UserSig 加密协议方案
  16. linux系统pyodbc安装与使用教程
  17. 指数函数 java_计算指数函数的算法
  18. 为什么很多人打游戏感觉很快乐,然而学习工作中的满足感却很低
  19. php 判断后缀名,PHP 文件类型判断代码
  20. dex字符串解密_某Xposed微信群发工具dex解密分析

热门文章

  1. android平板主题加字体,Android工具栏中心标题和自定义字体
  2. Vuetify Icon Picker
  3. 摄影技巧初级入门知识
  4. idea开发web项目,路径localhost:8080后去除 项目名+_war_exploded 的方法
  5. 台式机属于网络计算机吗,台式电脑没网络是怎么回事
  6. SQL中count和case when结合使用统计某个条件下不重复的记录数
  7. 栈与堆、浅拷贝与深拷贝以及什么是闭包
  8. 使用Jmeter进行性能测试及性能监控平台搭建
  9. 【ESP32最全学习笔记(基础篇)——4.ESP32 引脚介绍】
  10. 【报告分享】罗振宇2022“时间的朋友”跨年演讲全文(附下载)