5.10显示从100到1000之间所有能被5和6整除的数,每行显示10个 package pro0910; public class Num’ {
public static void main(String[] args) { int a = 0;
for (int i = 100; i < 1000; i++) { if (i % 5 == 0 || i % 6 == 0) { System.out.print(i + \ a += 1;
if (a == 10) {
System.out.println(); a = 0; } } } } }
5.17编写程序,提示用户输入一个在1到15之间的整数,然后显示一个金字塔形状
package pro0910;
import java.util.Scanner; public class Text {
public static void main(String[] args) { Scanner in=new Scanner(System.in);
System.out.print(\输入一个在1到15之间的整数:\ int line =in.nextInt(); for(int i=1;i<=line;i++){
for(int j=0;j 5.23演示抵消错误,n取50000 package pro0910; public class Wrong { public static void main(String[] args) { double sum1 = 0; double sum2 = 0; for (int i = 1; i < 50001; i++) { sum1 = sum1 + 1.0 / i; } for (int i = 50000; i > 0; i--) { sum2 = sum2 + 1.0 / i; } System.out.println(\从左往右加sum1=\ System.out.print(\从右往左加sum2=\ } } 5.26计算e,使用下面的数列可以近似计算e package pro0910; public class E { public static void main(String[] args) { double sum = 1; double e = 1; for (int i = 10000; i < 110000; i+=10000) { for (int j=1;j System.out.println(\当i=\时,e=\ } } } 5.31计算CD价值 package pro0910; import java.util.Scanner; public class CD { public static void main(String[] args) { Scanner in=new Scanner(System.in); System.out.print(\请输入金额:\ double money=in.nextDouble(); System.out.print(\请输入年利率:\ double rate=in.nextDouble(); System.out.print(\请输入月份数:\ int month=in.nextInt(); System.out.println(\ for (int i=1;i money=money+money*rate/1200; System.out.println(i+\ } } } 5.34剪刀石头布 public class Game { private static int i=0; private static int j=0; public static void main(String[] args) { for (int n=1;n<100;n++){ System.out.println(\输入一个数:0是剪刀,1是石头,2是布\ Scanner in = new Scanner(System.in); System.out.print(\请输入你的选择:\ int choose=in.nextInt(); int computer=(int)(Math.random()*3+0); System.out.println(\电脑的选择:\ game(choose,computer); if (i==2||j==2){System.out.print(\游戏结束\ System.out.println(); } } public static void game(int n1,int n2){ if (n1==n2){ System.out.println(\平局\ }else if (n1==0){ if (n2==1){j++; System.out.println(\你输了!\ } else {i++; System.out.println(\你赢了!\ }else if(n1==1){ if (n2==0){i++; System.out.println(\你赢了!\ } else {j++; System.out.println(\你输了!\ }else { if (n2==0){j++; System.out.println(\你输了!\ } else {i++; System.out.println(\你赢了!\ } } }