package draft_1;import java.util.Scanner;//输入包括两个运算量和一个运算符(+、-、*、/)的算术表达式,计算并输出运算结果publicclassText{publicstaticvoidmain(String[] args){
Scanner cin =newScanner(System.in);double a,b;
String s;
a = cin.nextDouble();
s = cin.next();
b = cin.nextDouble();if("+".equals(s))
System.out.println(a+"+"+b+"="+(a+b));if("-".equals(s))
System.out.println(a+"-"+b+"="+(a-b));if("*".equals(s))
System.out.println(a+"*"+b+"="+(a*b));if("/".equals(s))
System.out.println(a+"/"+b+"="+(a/b));}}
任意输入3条边的边长,计算三角形的面积(需要判定输入的三边是否可以构成三角形)
package draft_1;import java.util.Scanner;//任意输入3条边的边长,计算三角形的面积(需要判定输入的三边是否可以构成三角形)publicclassText{publicstaticvoidmain(String[] args){
Scanner cin =newScanner(System.in);double a,b,c,d;
a = cin.nextDouble();
b = cin.nextDouble();
c = cin.nextDouble();
d =(a+b+c)/2;boolean p;
p =Judge(a,b,c);if(p){
System.out.println(Math.sqrt(d*(d-a)*(d-b)*(d-c)));}else{
System.out.println("无法构成三角形");}}publicstaticbooleanJudge(double a,double b,double c){if((a+b)>c&&(a+c)>b&&(b+c)>a){returntrue;}elsereturnfalse;}}
输入任意一个整数,求其逆序数并输出,例如,输入1234,输出4321。
package draft_1;import java.util.Scanner;//输入任意一个整数,求其逆序数并输出,例如,输入1234,输出4321publicclassText{publicstaticvoidmain(String[] args){
Scanner cin =newScanner(System.in);int a, b =0, c =0;
a = cin.nextInt();while(a!=0){
b = a%10;
a = a/10;
c = c*10+b;}
System.out.println(c);}}
package draft_1;//使用级数求近似值(计算精度自定)publicclassText{publicstaticvoidmain(String[] args){double n =1, i =-1, j =-1;double a =0, b =0;while((2*n-1)<1000000){
j = j*i;
b =1/(2*n-1);
a = a+j*b;
n++;}
System.out.println(4*a);}}
根据x的值,按下式计算y的值,并保留小数点后2位有效数字(实现四舍五入)。
package draft_1;import java.util.Scanner;//根据x的值,按给定公式计算y的值,并保留小数点后2位有效数字(实现四舍五入)publicclassText{publicstaticvoidmain(String[] args){
Scanner cin =newScanner(System.in);double x,r,t;
x = cin.nextDouble();if(x>=1&&x<2)
r =3*x-5;elseif(x>=2&&x<4){
t = Math.cos(Math.toDegrees(x));
r =2*t+1;}elseif(x>=4&&x<6)
r = Math.sqrt(x*x+1);else
r = x*x-4*x+5;
System.out.println(String.format("%.2f",r));}}
从键盘连续输入任意个整数,(当输入为0 时,结束输入),分别求其中正数、负数的平均值,并输出结果。package draft_1;import java.util.Scanner;public class Text { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = 0,x,y = 0; double average; x = cin.nextInt(.