The six most common Java computing questions are:
1. 3 white balls 3 Red Balls 6 black balls random 8 balls, calculate all 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 ("with" + 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. Check whether the date format is correct.
Import java. util. warning; public class Date {public static void main (String [] args) {@ SuppressWarnings ("resource") // cancel the alarm for input when input = new warning (System. in); // declare the scanner variable System. out. println ("Enter ---- year -- month -- day"); // The system prompts you to enter int y = input. nextInt (); int m = input. nextInt (); int d = input. nextInt (); if (y> = 1900 & y <= 2050 & m> = 1 & m <= 12 & d> = 1 & d <= 31) System. out. print ("date is correct"); else System. out. print ("incorrect date ");}}
4. Computing 1 + 2/3 + 3/5 + 4/7 + 5/9... The sum of the first 20 items
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 the principal, interest rate, and duration to calculate the deposit (in the form of a 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 ("deposit amount of 300000 Yuan 10 years later" + CBM (300000, 0.07, 20); System. out. println ("deposit amount of 200000 yuan 20 years later" + CBM (200000, 0.06, 20 ));}}
6. Calculate the area of the Pentagon. Input r to calculate area s
Import java. util. warning; public class Circular {public static void main (String [] args) {@ SuppressWarnings ("resource") // cancel the alarm on input using input = new warning (System. in); // declare the scanner variable System. out. println ("Enter the Pentagon radius"); // The system prompts you 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 );}}