1.
// es01.java: Simple Method Use Import Tio.console; Class Es01 {Public Static Void Main (String [] args) {system.out.println ("Type Your Age:"); int tentage = console.in.readint (); System.out.Println ("Happy Birthday to you!"); PrintMessage (intage); // Method Call System.out.println ("Have A Nice Year!");} // definition of method printmessage static Void PrintMessage (int INTAGE) {IF (intage) System.out.Println ("you are" intage "Year OLD!"); Else System.Out.println ("You Are" "Years OLD! ");}}
2.
// es02.java: Simple method use import tio.console; class es02 {public static void main (string [] args) {system.out.println ("Type Your Age:"); int = console.in.readint (); System.out.Println ("Happy Birthday to you!"); PrintMessage (INTN); // Method Call System.Out.println ("Have a nice year!");} // definition of method printmessage static Void PrintMessage (int INTAGE) {IF (intage) System.out.Println ("you are" intage "Year OLD!"); Else System.Out.println ("You Are" "Years OLD! ");}}
3.
// es03.javaclass es03 {public static void main (string [] args) {system.out.println ("a Table of PowerS"); system.out.println ("----------- ------ / N "); System.out.Println (" Integer / Tsquian / Tcube / tquartic / tquintic "); system.out.println (" ----- / t ---- - / T ---- / t ------- / t ------- "); for (int INTI = 1; inti <= 25; inti ) {system.out.println INTI "/ T" Square (inti) "/ t" cube (inti) "/ t" quartic (inti) "/ t" quintic (inti));}} static int square (int Square) intNum) {return intNum * intNum;} static int cube (int intNum) {return intNum * intNum * intNum;} static int quartic (int intNum) {return square (intNum) * square (intNum);} static int quintic (int INTNUM) {Return Square (INTNUM) * CUBE (INTNUM);}} 4.
// es04.javaclass es04 {public static void main (string [] args) {} static int max (int x, int y) {if (x> y) returnix x; else returno (Double X) Double Y) {if (x> y) Return X; else returno y;}}
5.
// es05.java import Tio. *; Class runsums {public static void main (string [] args) {system.out.println ("Type a number:"); int int4t = console.in.readint (); Printbanner (); Propheadings (); readandprintdata (intcount);} // printbanner, printings and readandprintData // definitions will go here static void printbanner () {system.out.println ("/ n" ******* ************************************* / N " " * Running SUMS, Minimums, And Maximums * / n " " *************************************************** * / N ");} static void printheadings () {system.out.println (" count / tiTEM / TSUM / TMINIMUM / TMAXIMUM ");} static void readandprintdata (int id) {int CNT = 0, SUM = 0, Item, smallest, biggest; if (intcount> 0) {item = console.in.readint (); CNT ; Sum = Sum item; smallest = biggest = item; system.out.prin TLN (CNT "/ T" Item "/ T" SUM "/ T" smallest "/ t" biggest); while (cnt! = intcount) {item = console.in.readint () ; Cnt ; Sum = SUM ITEM; Smallst = min (item, smallest); Biggest = max (item, biggest); System.out.Println (CNT "/ T" item "/ t" sum " / t " smallest " / t " biggest);
}}} System.out.println ("Print Complete.");} Static int min (int A, int b) {IF (a b) Return A; ELSE RETURN B;}} 6.
// ES06.java import tio *;. Class ES06 {public static void main (String [] args) {printBanner (); printHeadings (); readAndPrintData ();} // printBanner, printHeadings and readAndPrintData // definitions will go here STATIC VOID Printbanner () {system.out.println ("/ n" "******************************** *********** / N " " * Running SUMS, Minimums, and Maximums * / N " " ******************* ************************* / N ");} static void printheadings () {system.out.println (" Count / TITEM / TSUM / TMINIMUM / TMAXIMUM ");} static void readandprintData () {INT CNT = 0, SUM = 0, Item, Smallst, Biggest; item = console.in.readint (); cnt ; sum = sum item; smallest = biggest = item; system.out.println (CNT "/ T" item "/ t" sum "/ t" smallest "/ t" biggest); while (console.in.hasmorelements ()) { item = console. IN.Readint (); cnt ; sum = sum item; smallest = min (item, smallest); biggest = max (item, biggest); system.out.println (CNT "/ t" item "/ t " SUM " / T " smallest " / t " biggest);}} static int min (int A, int b) {IF (a B) Return A; Else Return B;}}
7.// es07.javaclass es07 {public static void main (string [] args) {// input the number of tosses in a row to try. Int Numtosses = 5; // Just Use 4 for testing // input the number of trials to run int numTrials = 10000;. // Use 10000 for testing // Perform the specified number of trials int numSuccesses = performTrials (numTosses, numTrials); // Print the results double probability = numSuccesses / (double) numTrials; System.out.println ( "Probability found in" numTrials "is" probability);} // perform numTrials simulated coin tosses // and return the number of successes static int performTrials (int numTosses, int numTrials) {System. Out.println ("Monte Carlo" Numtosses "In A Row Heads"); int NumSuccesses = 0; for (int trials = 0; trials 8. // es08.javaclass es08 {public static void main (string [] args) {// input the number of tosses in a row to try. Int Numtosses = 6; // Just Use 6 for testing // input the number of trials to run int numTrials = 10000;. // Use 10000 for testing // Perform the specified number of trials int numCount = 10; int numSuccesses = performTrials (numCount, numTosses, numTrials); // Print the results double probability = numSuccesses / (double) numTrials; System.out.println ( "Probability found in" numTrials "is" probability);} // perform numTrials simulated coin tosses // and return the number of successes static int performTrials (int numCount, int Numtosses, int Numtrials) {System.out.Println ("Monte Carlo" Numtosses "In a Row Heads"); int NumSuccesses = 0; for (int trials = 0; trials // es09.javaclass es09 {public static void main (string [] args) {// input the number of tosses in a row to try. Int Numtosses = 5; // Just Use 5 for testing // input the number of in trials to run int numTrials = 1000000;. // Use 10000 for testing // Perform the specified number of trials int numCount = 10; int numSuccesses = performTrials (numCount, numTosses, numTrials); // Print the results double probability = numSuccesses / (double) numTrials; System.out.println ( "Probability found in" numTrials "is" probability);} // perform numTrials simulated coin tosses // and return the number of successes static int performTrials (int numCount, int Numtosses, int Numtrials) {system.out.println ("Monte Carlo" Numtosses "in a row heads"); int NumSuccesses = 0; for (int trials = 0; trials // ES10.java import tio *; class ES10 {public static void main (String [] args) {System.out.println ( "Type width, height and Text:");. Int intHeight, intWidth; String strText; intWidth = Console.in.readInt (); intHeight = Console.in.readInt (); strText = Console.in.readWord (); drawBox (intWidth, intHeight, strText);} static void drawBox (int intWidth, int intHeight, String strText) {drawLine (intWidth, strText); drawSides (intHeight, intWidth, strText); drawLine (intWidth, strText);} static void drawLine (int intWidth, String strText) {for (int intI = 0; intI // ES11.javaclass ES11 {public static void main (String [] args) {int intDays = 10; weatherReport (intDays);} private static void weatherReport (int intDays) {double dblWeather; for (int intI = 0; intI < INTDAYS; INTI ) {dblweather = math.random () * 3; if (dblweather> 2) System.out.println ("CLODY"); Else IF (DBLweather> 1) System.out.println ("Sunny); Else System.out.println ("Rainy");}}} 12. // es12.javaclass es12 {public static void main (string [] args) {switch (10 * math.random ()) {casse 0: break; case 1: breaf; case 2: break; cas 3: Break; Case 4: Break; Case 5: Break; Case 6: Break; Case 7: Break; Case 8: Break; Case 9: Break;}}} 13. // ES13.javaclass ES13 {public static void main (String [] args) {double dblX1 = 0.0, dblX2 = 10.0, dblStep = 0.01; func (dblX1, dblX2, dblStep);} static void func (double dblX1, double dblX2 , double dblStep) {double dblMin, dblMax, dblFunc; if (dblX1 // es14.javaclass es14 {public static void main (String [] args) {double a = 0.0, b = 10.0, x, step = 0.001; double dblmin, dblx; x = a; / * start at one end * / DBLMIN = f (x); dblx = x; while (f (x)! = 0.0 && x
// es15.javaclass es15 {public static void main (string [] args) {double a = 0.0, b = 5.0, EPS = 0.00001; double root = 0.0, residual; while (b - a> eps) {root = A b) / 2.0; residual = f (root); if (residual> 0) B = root; else a = root;} system.out.println ("root is" root);} static double f (double x) {RETURN (Math.Pow (Math.e, Math.Pow (x, 2)) - 10.0);}} 16. // es16.javaclass es16 {public static void main (string [] args) {double a = 0.0, b = 5.0; double root = 0.0, result, Times = 100; for (int INTI = 0; inti // es17.java import Tio.Console; Class Es17 {public static void main (string [] args) {// initializes the number of money. INT INTMONEY = 100; system.out.println ("You Have 100 Dollars Left."); // Cycle, if you need to quit, enter the number of gambling money 0 While (INTMONEY> 0) {// The player bets System.out. Println ("Put Down Some Money, / N" "Put 0 for quit."); int rt = console.in.readint (); if (intbet> INTMONEY) Continue; if (INTBET == 0) Break; / / Gamer rolls int INTDISC = disc (); system.out.println ("you throw out: intDisc); // Judgment result INTMONEY = Result (INTMONEY, INTBET, INTDISC);}} static int result INTMONEY, INT INTBET, INT INTDISC) {// Judgment Swith Switch (INTDISC) {Case 7: Case 11: INTMONEY = Playerwin (INTMONEY, INTBET); Break; Case 2: Case 12: INTMONEY = Playerlose (INTMONEY, INTBET); Break; default: // Assignment Point INT INTPOINT = INTDISC; System.Out.println ("Your Point IS" INTPOINT); / / Continue to throw the color until 7 or Point INTDISC = DISC (); system.out.println ("Rethrow: INTDISC); While (intDisc! = 7 && intDisc! = intPoint) {INTDISC = disc (); system.out.println ("Rethrow: INTDISC);} if (intDisc == 7) INTMONEY = Playerlose (INTMONEY, INTBET); Else INTMONEY = Playerwin (INTMONEY, INTBET); } Return INTMONEY;} static int 4; result = result (int) (math.random () * 6) 1; result = result (int) (Math.random () * 6 ) 1; return result;} static int playerwin (int INTMONEY, INT INTBET) {INTMONEY = INTMONEY INTBET; System.out.Println ("You Win and Earn Some Money / N" "You Have" INTMONEY " "} static int timlose;} static int pLayerlose (int INTMONEY, INT INTBET) {INTMONEY = INTMONEY - INTBET; if (INTMONEY == 1 || INTMONEY == 0) System.out.println (" You Lose. / N " " You Have " INTMONEY " Dollar Left. "); Else System.Out.println (" You Lose./N " " You Have " INTMONEY " DOLLARS LEFT. "); Return IntMoney; }} 18. // es18.javaclass es18 {public static void main (string [] args) {char chrx1 = 'a', chrx2 = 'z'; charPrint (chrx1, chrx2);} static void charprint (char chrx1, char chrx2) { IF (chrx1 19. // es19.javaclass es19 {public static void main (string [] args) {char chrx1 = 'c', chrx2 = 'g'; PrintRange (Chrx1, chrx2);} Static Void PrintRange (Char first, char last) { IF (first // es20.javaclass es20 {public static void main (string [] args) {int n = 40; system.out.println (Fibonacci (n));} static long fibonacci (int N) {INT f0 = 0, F1 = 1, F2; F2 = f0 f1; for (INT i = 2; i <= n; i ) {f2 = f0 f1; f0 = f1; f1 = f2;} returnif2;}}