java 学习第二天小练习

1.从控制台输入学员王浩3门课程成绩,编写程序实现

ChengJi

(1)数学课和英语课的分数之差

(2)3门课的平均分

java 学习第二天小练习

代码如下:

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; min-height: 22.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #4e9072 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #3933ff }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #7e504f }
span.s1 { color: #931a68 }
span.s2 { color: #7e504f }
span.s3 { color: #000000 }
span.s4 { color: #91afcb }
span.s5 { color: #4e9072 }
span.s6 { text-decoration: underline; color: #7e504f }
span.s7 { color: #0326cc }
span.s8 { color: #3933ff }
span.Apple-tab-span { white-space: pre }

package lianXiTi;

import java.util.Scanner;

public class ChengJi2_5 {

public static void main(String[] args) {

// TODO Auto-generated method stub

/*

* 要求:从控制台输入学院王浩三门课程成绩,编写程序实现:

* 1)数学课和英语课的分数之差

* 2)3门课的平均分

*/

Scanner in=new Scanner(System.in );

System.out.println(" 请输入王浩的语文成绩:");

int chinese=in.nextInt();

System.out.println(" 请输入王浩的数学成绩");

int math=in.nextInt();

System.out.println("请输入王浩的英语成绩");

int english=in.nextInt();

System.out.println("---------------------------------------------------------\n"+"语文\t 数学\t英语\t\n"+chinese+"\t"+math+"\t"+ english+"\n---------------------------------------------------------\n");

int cha=math-english;//数学和英语的成绩差

System.out.println("数学和英语的成绩差是:"+cha);

int average=(chinese+math+english)/3;

System.out.println( "三门课的平均分是:"+average);

}

}

2.已知圆的半径radius= 1.5,求其面积

MianJi

提示:

     double pi = 3.14159; //
圆周率

     double radius = 1.5; // 半径

     double area = pi * radius * radius; // 计算圆面积

java 学习第二天小练习

代码如下:

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; min-height: 22.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #931a68 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #4e9072 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #7e504f }
span.s1 { color: #931a68 }
span.s2 { color: #000000 }
span.s3 { color: #7e504f }
span.s4 { color: #91afcb }
span.s5 { color: #4e9072 }
span.s6 { color: #0326cc }
span.Apple-tab-span { white-space: pre }

package lianXiTi;

public class mianji {

public static void main(String[] args) {

// TODO Auto-generated method stub

/*

* 已知圆的半径 radius=1.5,求其面积,

* 提示:

* double PI=3.14159;

* double=radius=1.5;

* double area=PI*radius*radius;

*  面积为7.068577499999999

*/

double PI=3.14159;

double radius=1.5;

double area=PI*radius*radius;

System.out.println(area);

}

}

3.根据天数(46)计算周数和剩余的天数

提示:

     int days = 46;   //
天数

     int week = days / 7;   // 星期

     int leftDay = days % 7;  // 剩余的天数

java 学习第二天小练习

代码如下:

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; min-height: 22.0px }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #4e9072 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Monaco; color: #7e504f }
span.s1 { color: #931a68 }
span.s2 { color: #7e504f }
span.s3 { color: #000000 }
span.s4 { color: #91afcb }
span.s5 { color: #4e9072 }
span.s6 { text-decoration: underline }
span.s7 { color: #0326cc }
span.s8 { color: #3933ff }
span.Apple-tab-span { white-space: pre }

package lianXiTi;

public class genJuTianShuJiSuanZhouShu {

public static void main(String[] args) {

// TODO Auto-generated method stub

/*

* 根据天数(46)计算周数和剩余的天数

* 提示: int days=46;

* int week=days/7;

* int leftDay=day%7;

*/

int days=46;

int week=days/7;

int leftDay=days%7;

System.out.println("总共"+days+"周数"+week+" 剩余的天数"+ leftDay);

}

}

4.实现一个数字加密器,加密规则是:加密结果 = (整数*10+5/2 + 3.14159,加密结果仍为一整数

java 学习第二天小练习

代码如下:

package pro_0307_01; import java.util.Scanner; public class JiaMi { public static void main(String[] args) { //使用户与控制台进行交互 Scanner in=new Scanner(System.in); System.out.println("请输入一个数:"); //接收从控制台输入的数据,赋值给变量num int num=in.nextInt(); System.out.println("原始数据是:"+num); int num2=(int)((num*10+5)/2+3.14159); System.out.println("加密后的结果是:"+num2); } }

p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 10.5px "Trebuchet MS"; color: #000000 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 10.5px "Trebuchet MS"; color: #000000; min-height: 12.0px }
li.li1 { margin: 0.0px 0.0px 13.0px 0.0px; text-align: justify; font: 16.0px "Times New Roman"; color: #000000 }
span.s1 { }
span.s2 { font: 16.0px "Songti SC" }
span.s3 { }
span.s4 { font: 10.5px "Songti SC" }
ol.ol1 { list-style-type: decimal }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 10.5px "Trebuchet MS"; color: #000000 }
li.li1 { margin: 0.0px 0.0px 13.0px 0.0px; text-align: justify; font: 16.0px "Songti SC"; color: #000000 }
span.s1 { font: 16.0px "Times New Roman" }
span.s2 { }
span.s3 { font: 16.0px "Times New Roman" }
span.s4 { font: 10.5px "Songti SC" }
ol.ol1 { list-style-type: decimal }
li.li1 { margin: 0.0px 0.0px 13.0px 0.0px; text-align: justify; font: 16.0px "Songti SC"; color: #000000 }
span.s1 { font: 16.0px "Times New Roman" }
span.s2 { }
span.s3 { font: 16.0px "Times New Roman" }
ol.ol1 { list-style-type: decimal }

上一篇:LeetCode 263


下一篇:利用 js 实现弹出蒙板(model)功能