1. 3 white balls, 3 red balls, 6 black balls, and randomly take out 8 balls to calculate all the results
public class Ball{ public static void main(String[] args){ int a=3,b=3,c=6,i=0; for (int x=0;x<=a;x++){ for (int y=0;y<=b;y++){ for (int z=0;z<=c;z++){ if (x+y+z==8){ System.out.println("Red ball" + x + "/t white ball" + y + "/t black ball" + z ); i++; } } } System.out.println("Have" + i + "result"); } }2. Digital pyramid
public class Pyramid { public static void main(String args[]){ for (int i=1; i<=32; i=i*2) { for (int k=1; k<=32/i; k=k*2)System.out.print("/t"); for (int j=1; j<=i; j=j*2)System.out.print("/t"+j); for (int m=i/2; m>=1; m=m/2) System.out.print("/t"+m); System.out.print("/n"); } } }3. Simple judgment on whether the date format is correct
import java.util.Scanner; public class Date{ public static void main(String[] args) { @SuppressWarnings("resource")//Cancel the alert for input Scanner input=new Scanner(System.in);//Declare the scanner variable System.out.println("Please enter ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (y>=1900&&y<=2050&&m>=1&&m<=12&&d>=1&&d<=31) System.out.print("Correct date"); else System.out.print("Incorrect date"); } }4. Calculate the sum of the first 20 items of 1+2/3+3/5+4/7+5/9…
public class Num{public static void main(String[] args) {double sum=0;for(int i=1;i<=10;i++) sum=sum+i/(2.0*i-1);System.out.println(sum);}}5. Give principal, interest rate, and years to calculate deposit (in function)
public class Bank { public static double CBM(double money,double interest,int years){ for(int i=1;i<=years;i++){ money = money *(1+ interest); } return money; } public static void main(String[] args) { System.out.println("The deposit amount of RMB 300,000 after 10 years is "+CBM(300,000,0.07,20)); System.out.println("200,000 yuan deposit amount after 20 years is "+CBM(200000,0.06,20)); } }6. Calculate the area of the pentagon. Enter r to find area s
import java.util.Scanner;public class Circular{ public static void main(String[] args) { @SuppressWarnings("resource")//Cancel the alarm for input Scanner input=new Scanner(System.in);//Declare the scanner variable System.out.println("Please enter the pentagon radius");//The system prompts to enter double r = input.nextDouble(); double S; S=5*(2*r*Math.sin(Math.PI/5)*(Math.pow(2*r*Math.sin(Math.PI/5), 2))/(4*Math.tan(Math.PI/5))); System.out.println("The area of the pentagon is "+S); } }