1,通过代码编写,输一段话:“今天是学习的第一天”
package java4;
public class practise {
public static void main(String[] args) {
System.out.println("今天是学习的第一天");
}
}
2,拼接打印:“XXX:我已经学习了JavaX年,我期望的工资是XXX”
package java4;
public class practise {
public static void main(String[] args) {
String name = "佐助";
int year = 5;
double salary = 5000.00;
System.out.println(name + ":我已经学习了Java" +year+"年,我期望的工资是" +salary );
}
}
3,定义两个整数,并进行加减乘除的运算
package java4;
public class practise {
public static void main(String[] args) {
double a = 4;
double b = 5;
System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
}
}
4,通过输入父亲和母亲的身高,运用公式计算出儿子和女儿的遗传身高
儿子身高(厘米)=(父亲身高+母亲身高)*1.08/2;
女儿身高(厘米)=(父亲身高*0.923+母亲身高)/2
package java4;
import java.util.Scanner;
public class practise {
public static void main(String[] args) {
System.out.println("请输入父亲的身高");
double fatherheight = new Scanner(System.in).nextDouble();
System.out.println("请输入母亲的身高");
double motherheight = new Scanner(System.in).nextDouble();
double sonheight = (fatherheight + motherheight)*1.08/2;
double daughterheight = (fatherheight*0.923 + motherheight)/2;
System.out.println("儿子的身高为:"+ sonheight +"厘米");
System.out.println("女儿的身高"+ daughterheight +"厘米");
}
}
5,通过重载输出九九乘法表
package java4;
public class practise {
public static void main(String[] args) {
int x=9;
print99(x);
}
public static void print99(int x){
for(int i=1;i<=x;i++){
for(int j=1;j<=i;j++){
System.out.print(j + "*" + i + "=" +(j*i)+ "\t");
}
System.out.println();
}
}
}
标签:Java,五题,double,练习,System,println,身高,public,out
From: https://blog.csdn.net/weixin_45449264/article/details/142464414