The Framework/Problem Paradox

Topic by John Doe

John Doe

Home Forums Philosophy The Framework/Problem Paradox

This topic contains 17 replies, has 5 voices, and was last updated by Gravel Pit  Gravel Pit 1 year, 1 month ago.

Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #880261
    +3
    John Doe
    John Doe
    Participant
    743

    The question of all problems is rooted in its framework. However no framework in itself is complete if it must be composed of and composes further frameworks.

    Hence all frameworks have an element of contradiction in these respects considering they are always incomplete and not self-referential with the progression of one framework necessitating the elimination of another (we see this in the evolution of computer languages and to some degree in logic).

    The question of the framework it literally dependent upon the foundations which form it as the foundations, as often “assumed” universal axioms, in turn are frameworks in themselves.

    Under these terms the question of universality is put to question as the foundations become the framework and the framework becomes the foundations.

    Under these terms the self referential, while simultaneously progressive, limits of geometry as “directed movement” provide this necessary dualism while maintaining a neutral third nature of existing as “is” considering the simple point, line and circle cannot be “doubted” within any course of reason without simultaneously applying these limits in one form or another through the form of math, logic or basic spatial reasoning (which is embodied in directed movement).

    Even standard language whether based in pure reason, empirical roots, or sophristy is still defined and determined as true or false according to these limits.

    #880292
    +2

    Anonymous
    1

    All problems should be viewed in comparison to the Absolute Cosmic reference point.

    Paradoxes are works of fiction conjured up by the imagination. They should be studied as psychological phenomena, nothing more.

    #880294
    +1
    Hmskl'd
    hmskl’d
    Participant
    6405

    Firmly rooted footing for secure foundation and framework.

    #880302
    John Doe
    John Doe
    Participant
    743

    All problems should be viewed in comparison to the Absolute Cosmic reference point.
    Paradoxes are works of fiction conjured up by the imagination. They should be studied as psychological phenomena, nothing more.

    Your first sentence says it all (if it implies what I believe you think it implies), point space is not only absolute but the origin of everything.

    I will post some small work on a theoretical 1 dimensional point as the foundation for everything, as well as the nature of 0d points space as the foundation of relativism.

    Paradoxes are the result of base division, where we take a phenomenon and seperate it. Paradoxes not only require a dualism but are inherently solvable by synthesis, hence they have a triadic quality.

    The nature of psychology cannot be seperate from physics, or religion, math…or anything of a practical nature as well. This is considering the premise everything originates and exists through 1 point.

    #880303
    +1
    John Doe
    John Doe
    Participant
    743

    Firmly rooted footing for secure foundation and framework.

    Recursion (Google or just think of Russian dolls) or a mirror effect (replication) is the foundation for framework, with both existing as inseparable components.

    Directed movement is foundation for all phenomenon.

    #880341
    +1
    Gravel Pit
    Gravel Pit
    Participant

    Satellite Data Codes
    Satellite Data Codes are used by telemetry stations, forecast centers and others to encode solar geophysical data obtained from satellite-based sensors.
    USXRA Codes
    Solar x-ray events..

    Example:

    Definition of symbols:

    USXRA comes from Solar X-RAy events

    I I I I I = station indicator

    Y = last digit of year
    MM = month of year, 01 = January, 02 = February, etc
    . DD = UT day of month

    SS = satellite
    06 = GOES-6
    07 = GOES-7
    08 = GOES-8
    09 = GOES-9
    E = energy range
    1 = .1-.8 nm
    NN = number of events

    0 = indicates that the begin time of the event follows
    HHmm = UT hour and minute of beginning of event

    0 = indicates that the maximum time of the event follows
    HHmm = UT hour and minute of maximum for event

    0 = indicates that the the end time of the event follows
    HHmm = UT hour and minute of end time of event

    Maximum Flux:
    Q = qualifier
    0 = uncertain data
    1 = certain data
    ab = x-ray flux in Wm-1 where ab = a.b
    S = sign of the exponent to apply to a.b
    0 = positive
    1 = negative
    p = power of ten to apply to a.b
    Note: abSp reported as 4192 would equal 4.1 x 10-1Wm-1

    Note: / is to be used for data not available.

    Integrated flux (start thru end):
    9 = qualifier
    ab x-ray integrated flux in Jm-1 where ab = a.b
    S = sign of the exponent to apply to a.b
    0 = positive
    1 = negative
    p = power of ten to apply to a.b
    Note: abSp reported as 5692 would equal 5.6 x 10-1Wm-1

    Note: / is to be used for data not available.

    Home | Site Map | Contact Us | Privacy Policy | Help

    ISES
    Message from the Director
    The History of ISES
    What Do We Do
    Constitution
    Organizational Structure
    Logo

    Members
    Space Weather Now
    Space Weather Effects
    Satellites
    Aviations
    Navigations
    Power Grids
    Communications
    Examples

    URSIgram Codes
    Geophysical Data Codes
    Alerts, Analasys & Forecasts Codes
    Radio Data Codes
    Optical Data Codes
    Satellite Data Codes
    Satellite Ionospheric Data Codes
    RWC and Specialized Codes

    #880343
    +1
    Gravel Pit
    Gravel Pit
    Participant

    Its a shot across the bow you f~~~ing s~~~christ bitch. DO not f~~~ with me

    #880345
    +1
    Gravel Pit
    Gravel Pit
    Participant

    .3 Conditionals and Loops

    In the programs that we have examined to this point, each of the statements is executed once, in the order given. Most programs are more complicated because the sequence of statements and the number of times each is executed can vary. We use the term control flow to refer to statement sequencing in a program.

    If statements. Most computations require different actions for different inputs.
    The following code fragment uses an if statement to put the smaller of two int values in x and the larger of the two values in y, by exchanging the values in the two variables if necessary.
    anatomy of an if statement
    Flip.java uses Math.random() and an if-else statement to print the results of a coin flip.
    The table below summarizes some typical situations where you might need to use an if or if-else statement.
    examples of conditionals

    While loops. Many computations are inherently repetitive. The while loop enables us to execute a group of statements many times. This enables us to express lengthy computations without writing lots of code.
    The following code fragment computes the largest power of 2 that is less than or equal to a given positive integer n.
    anatomy of a while loop
    TenHellos.java prints “Hello World” 10 times.
    PowersOfTwo.java takes an integer command-line argument n and prints all of the powers of 2 less than or equal to n.
    For loops. The for loop is an alternate Java construct that allows us even more flexibility when writing loops.
    For notation. Many loops follow the same basic scheme: initialize an index variable to some value and then use a while loop to test an exit condition involving the index variable, using the last statement in the while loop to modify the index variable. Java’s for loop is a direct way to express such loops.
    anatomy of a for loop
    Compound assignment idioms. The idiom i++ is a shorthand notation for i = i + 1.
    Scope. The scope of a variable is the part of the program that can refer to that variable by name. Generally the scope of a variable comprises the statements that follow the declaration in the same block as the declaration. For this purpose, the code in the for loop header is considered to be in the same block as the for loop body.
    Nesting. The if, while, and for statements have the same status as assignment statements or any other statements in Java; that is, we can use them wherever a statement is called for. In particular, we can use one or more of them in the body of another statement to make compound statements. To emphasize the nesting, we use indentation in the program code.
    DivisorPattern.java has a for loop whose body contains a for loop (whose body is an if-else statement) and a print statement. It prints a pattern of asterisks where the ith row has an asterisk in each position corresponding to divisors of i (the same holds true for the columns).
    MarginalTaxRate.java computes the marginal tax rate for a given income. It uses several nested if-else statements to test from among a number of mutually exclusive possibilities.
    Loop examples.
    examples of loops
    Applications. The ability to program with loops and conditionals immediately opens up the world of computation to us.
    Ruler subdivisions. RulerN.java takes an integer command-line argument n and prints the string of ruler subdivision lengths. This program illustrates one of the essential characteristics of loops—the program could hardly be simpler, but it can produce a huge amount of output.
    Harmonic numbers
    Finite sums. The computational paradigm used in PowersOfTwo.java is one that you will use frequently. It uses two variables—one as an index that controls a loop, and the other to accumulate a computational result. Program HarmonicNumber.java uses the same paradigm to evaluate the sum
    Hn=11+12+13+14+…+1n
    These numbers, which are known as the harmonic numbers, arise frequently in the analysis of algorithms.
    Newton’s method. Newton’s methodSqrt.java uses a classic iterative technique known as Newton’s method to compute the square root of a positive number x: Start with an estimate t. If t is equal to x/t (up to machine precision), then t is equal to a square root of x, so the computation is complete. If not, refine the estimate by replacing t with the average of t and x/t. Each time we perform this update, we get closer to the desired answer.
    Number conversion. Binary.java prints the binary (base 2) representation of the decimal number typed as the command-line argument. It is based on decomposing the number into a sum of powers of 2. For example, the binary representation of 106 is 11010102, which is the same as saying that 106 = 64 + 32 + 8 + 2. To compute the binary representation of n, we consider the powers of 2 less than or equal to n in decreasing order to determine which belong in the binary decomposition (and therefore correspond to a 1 bit in the binary representation).
    Gambler’s ruin. gambler’s ruin Suppose a gambler makes a series of fair $1 bets, starting with $50, and continue to play until she either goes broke or has $250. What are the chances that she will go home with $250, and how many bets might she expect to make before winning or losing? Gambler.java is a simulation that can help answer these questions. It takes three command-line arguments, the initial stake ($50), the goal amount ($250), and the number of times we want to simulate the game.
    Prime factorization. Factors.java takes an integer command-line argument n and prints its prime factorization. In contrast to many of the other programs that we have seen (which we could do in a few minutes with a calculator or pencil and paper), this computation would not be feasible without a computer.
    Other conditional and loop constructs. To be complete, we consider four more Java constructs related to conditionals and loops. They are used much less frequently than the if, while, and for statements that we’ve been working with, but it is worthwhile to be aware of them.
    Break statements. In some situations, we want to immediate exit a loop without letting it run to completion. Java provides the break statement for this purpose. Prime.java takes an integer command-line argument n and prints true if n is prime, and false otherwise. There are two different ways to leave this loop: either the break statement is executed (because n is not prime) or the loop-continuation condition is not satisfied (because n is prime).
    Note that the break statement does not apply to if or if-else statements. In a famous programming bug, the U.S. telephone network crashed because a programmer intended to use a break statement to exit a complicated if statement.

    Continue statements. Java also provides a way to skip to the next iteration of a loop: the continue statement. When a continue is executed within the body of a for loopy, the flow of control transfers directly to the increment statement for the next iteration of the loop.
    Switch statements. The if and if-else statements allow one or two alternatives. Sometimes, a computation naturally suggests more than two mutually exclusive alternatives. Java provides the switch statement for this purpose. NameOfDay.java takes an integer between 0 and 6 as a command-line argument and uses a switch statement to print the corresponding name of the day (Sunday to Saturday).
    Do–while loops. A do-while loop is almost the same as a while loop except that the loop-continuation condition is omitted the first time through the loop. RandomPointInCircle.java sets x and y so that (x, y) is randomly distributed inside the circle centered at (0, 0) with radius 1.
    do-while loop
    With Math.random() we get points that are randomly distributed in the 2-by-2 square center at (0, 0). We just generate points in this region until we find one that lies inside the unit disk. We always want to generate at least one point so a do-while loop is most appropriate. We must declare x and y outside the loop since we will want to access their values after the loop terminates.

    We don’t use the following two flow control statements in this textbook, but include them here for completeness.
    Conditional operator. The conditional operator ?: is a ternary operator (three operands) that enables you to embed a conditional within an expression. The three operands are separated by the ? and : symbols. If the first operand (a boolean expression) is true, the result has the value of the second expression; otherwise it has the value of the third expression.
    int min = (x < y) ? x : y;
    Labeled break and continue statements. The break and continue statements apply to the innermost for or while loop. Sometimes we want to jump out of several levels of nested loops. Java provides the labeled break and labeled continue statements to accomplish this. Here is an example.
    Exercises
    Write a program AllEqual.java that takes three integer command-line arguments and prints equal if all three are equal, and not equal otherwise.
    Write a program RollLoadedDie.java that prints the result of rolling a loaded die such that the probability of getting a 1, 2, 3, 4, or 5 is 1/8 and the probability of getting a 6 is 3/8.
    Rewrite TenHellos.java to make a program Hellos.java that takes the number of lines to print as a command-line argument. You may assume that the argument is less than 1000. Hint: consider using i % 10 and i % 100 to determine whether to use “st”, “nd”, “rd”, or “th” for printing the ith Hello.
    Write a program FivePerLine.java that, using one for loop and one if statement, prints the integers from 1000 to 2000 with five integers per line. Hint: use the % operator.
    Write a program FunctionGrowth.java that prints a table of the values of ln n, n, n ln n, n2, n3, and 2n for n = 16, 32, 64, …, 2048. Use tabs (‘\t’ characters) to line up columns.
    What is the value of m and n after executing the following code?
    int n = 123456789;
    int m = 0;
    while (n != 0) {
    m = (10 * m) + (n % 10);
    n = n / 10;
    }
    What does the following code print out?
    int f = 0, g = 1;
    for (int i = 0; i <= 15; i++) {
    System.out.println(f);
    f = f + g;
    g = f – g;
    }
    Unlike the harmonic numbers, the sum 1/1 + 1/4 + 1/9 + 1/16 + … + 1/n2 does converge to a constant as n grows to infinity. (Indeed, the constant is π2 / 6, so this formula can be used to estimate the value of π.) Which of the following for loops computes this sum? Assume that n is an int initialized to 1000000 and sum is a double initialized to 0.
    (a) for (int i = 1; i <= n; i++)
    sum = sum + 1 / (i * i);

    (b) for (int i = 1; i <= n; i++)
    sum = sum + 1.0 / i * i;

    (c) for (int i = 1; i <= n; i++)
    sum = sum + 1.0 / (i * i);

    (d) for (int i = 1; i <= n; i++)
    sum = sum + 1 / (1.0 * i * i);
    Modify Binary.java to get a program Modify Kary.java that takes a second command-line argument K and converts the first argument to base K. Assume the base is between 2 and 16. For bases greater than 10, use the letters A through F to represent the 11th through 16th digits, respectively.
    Write a program code fragment that puts the binary representation of a positive integer n into a String variable s.
    Creative Exercises
    Ramanujan’s taxi. S. Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him in the hospital one day, Hardy remarked that the number of his taxi was 1729, a rather dull number. To which Ramanujan replied, “No, Hardy! No, Hardy! It is a very interesting number. It is the smallest number expressible as the sum of two cubes in two different ways.” Verify this claim by writing a program Ramanujan.java that takes an integer command-line argument n and prints all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways – find distinct positive integers a, b, c, and d such that a3 + b3 = c3 + d3. Use four nested for loops.
    Now, the license plate 87539319 seems like a rather dull number. Determine why it’s not.

    Checksums. The International Standard Book Number (ISBN) is a 10 digit code that uniquely specifies a book. The rightmost digit is a checksum digit which can be uniquely determined from the other 9 digits from the condition that d1 + 2d2 + 3d3 + … + 10d10 must be a multiple of 11 (here di denotes the ith digit from the right). The checksum digit d1 can be any value from 0 to 10: the ISBN convention is to use the value X to denote 10. Example: the checksum digit corresponding to 020131452 is 5 since is the only value of d1 between 0 and and 10 for which d1 + 2*2 + 3*5 + 4*4 + 5*1 + 6*3 + 7*1 + 8*0 + 9*2 + 10*0 is a multiple of 11. Write a program ISBN.java that takes a 9-digit integer as a command-line argument, computes the checksum, and prints the 10-digit ISBN number. It’s ok if you don’t print any leading 0s.
    Exponential function. Assume that x is a positive variable of type double. Write a program Exp.java that computes e^x using the Taylor series expansion
    ex=1+x+x22!+x33+x44!+…
    Trigonometric functions. Write two programs Sin.java and Cos.java that compute sin x and cos x using the Taylor series expansions
    sinx=x−x33!+x55!−x77!+…
    cosx=1−x22!+x44!−x66!+…
    Game simulation. In the game show Let’s Make a Deal, a contestant is presented with three doors. Behind one door is a valuable prize, behind the other two are gag gifts. After the contestant chooses a door, the host opens up one of the other two doors (never revealing the prize, of course). The contestant is then given the opportunity to switch to the other unopened door. Should the contestant do so? Intuitively, it might seem that the contestant’s initial choice door and the other unopened door are equally likely to contain the prize, so there would be no incentive to switch. Write a program MonteHall.java to test this intuition by simulation. Your program should take an integer command-line argument n, play the game n times using each of the two strategies (switch or don’t switch) and print the chance of success for each strategy. Or you can play the game here.
    Euler’s sum-of-powers conjecture. In 1769 Leonhard Euler formulated a generalized version of Fermat’s Last Theorem, conjecturing that at least n nth powers are needed to obtain a sum that is itself an nth power, for n > 2. Write a program Euler.java to disprove Euler’s conjecture (which stood until 1967), using a quintuply nested loop to find four positive integers whose 5th power sums to the 5th power of another positive integer. That is, find a, b, c, d, and e such that a5 + b5 + c5 + d5 = e5. Use the long data type.
    Web Exercises
    Write a program RollDie.java that generates the result of rolling a fair six-sided die (an integer between 1 and 6).
    Write a program that takes three integer command-line arguments a, b, and c and print the number of distinct values (1, 2, or 3) among a, b, and c.
    Write a program that takes five integer command-line arguments and prints the median (the third largest one).
    (hard) Now, try to compute the median of 5 elements such that when executed, it never makes more than 6 total comparisons.
    How can I create in an infinite loop with a for loop?
    Solution: for(;;) is the same as while(true).

    What’s wrong with the following loop?
    boolean done = false;
    while (done = false) {

    }
    The while loop condition uses = instead of == so it is an assignment statement (which makes done always false and the body of the loop will never be executed). It’s better to style to avoid using ==.
    boolean done = false;
    while (!done) {

    }
    What’s wrong with the following loop that is intended to compute the sum of the integers 1 through 100?
    for (int i = 1; i <= N; i++) {
    int sum = 0;
    sum = sum + i;
    }
    System.out.println(sum);
    The variable sum should be defined outside the loop. By defining it inside the loop, a new variable sum is initialized to 0 each time through the loop; also it is not even accessible outside the loop.
    Write a program Hurricane.java that that takes the wind speed (in miles per hour) as an integer command-line argument and prints whether it qualifies as a hurricane, and if so, whether it is a Category 1, 2, 3, 4, or 5 hurricane. Below is a table of the wind speeds according to the Saffir-Simpson scale.
    CategoryWind Speed (mph)
    174 – 95
    296 – 110
    3111 – 130
    4131 – 155
    5155 and above
    What is wrong with the following code fragment?
    double x = -32.2;
    boolean isPositive = (x > 0);
    if (isPositive = true) System.out.println(x + ” is positive”);
    else System.out.println(x + ” is not positive”);
    Solution: It uses the assignment operator = instead of the equality operator ==. A better solution is to write if (isPositive).

    Change/add one character so that the following program prints 20 xs. There are two different solutions.
    int i = 0, n = 20;
    for (i = 0; i < n; i–)
    System.out.print(“x”);
    Solution: Replace the i < n condition with -i < n. Replace the i– with n–. ( In C, there is a third: replace the < with a +.)
    What does the following code fragment do?
    if (x > 0);
    System.out.println(“positive”);
    Solution: always prints positive regardless of the value of x because of the extra semicolon after the if statement.

    RGB to HSB converter. Write a program RGBtoHSV.java that takes an RGB color (three integers between 0 and 255) and transforms it to an HSB color (three different integers between 0 and 255). Write a program HSVtoRGB.java that applies the inverse transformation.
    Boys and girls. A couple beginning a family decides to keep having children until they have at least one of either sex. Estimate the average number of children they will have via simulation. Also estimate the most common outcome (record the frequency counts for 2, 3, and 4 children, and also for 5 and above). Assume that the probability p of having a boy or girl is 1/2.
    What does the following program do?
    public static void main(String[] args) {
    int N = Integer.parseInt(args[0]);
    int x = 1;
    while (N >= 1) {
    System.out.println(x);
    x = 2 * x;
    N = N / 2;
    }
    }
    Solution: Prints all of the powers of 2 less than or equal to n.
    Boys and girls. Repeat the previous question, but assume the couple keeps having children until they have another child which is of the same sex as the first child. How does your answer change if p is different from 1/2?
    Surprisingly, the average number of children is 2 if p = 0 or 1, and 3 for all other values of p. But the most likely value is 2 for all values of p.

    Given two positive integers a and b, what result does the following code fragment leave in c
    c = 0;
    while (b > 0) {
    if (b % 2 == 1) c = c + a;
    b = b / 2;
    a = a + a;
    }
    Solution: a * b.

    Write a program using a loop and four conditionals to print
    12 midnight
    1am
    2am

    12 noon
    1pm

    11pm
    What does the following program print?
    public class Test {
    public static void main(String[] args) {
    if (10 > 5);
    else; {
    System.out.println(“Here”);
    };
    }
    }
    Alice tosses a fair coin until she sees two consecutive heads. Bob tosses another fair coin until he sees a head followed by a tail. Write a program to estimate the probability that Alice will make fewer tosses than Bob? Solution: 39/121.
    Rewrite DayOfWeek.java from Exercise 1.2.29 so that it prints the day of the week as Sunday, Monday, and so forth instead of an integer between 0 and 6. Use a switch statement.
    Number-to-English. Write a program to read in a command line integer between -999,999,999 and 999,999,999 and print the English equivalent. Here is an exhaustive list of words that your program should use: negative, zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand, million . Don’t use hundred, when you can use thousand, e.g., use one thousand five hundred instead of fifteen hundred. Reference.
    Gymnastics judging. A gymnast’s score is determined by a panel of 6 judges who each decide a score between 0.0 and 10.0. The final score is determined by discarding the high and low scores, and averaging the remaining 4. Write a program GymnasticsScorer.java that takes 6 real command line inputs representing the 6 scores and prints their average, after throwing out the high and low scores.
    Quarterback rating. To compare NFL quarterbacks, the NFL devised a the quarterback rating formula based on the quarterbacks number of completed passes (A), pass attempts (B), passing yards (C), touchdown passes (D), and interception (E) as follows:
    Completion ratio: W = 250/3 * ((A / B) – 0.3).
    Yards per pass: X = 25/6 * ((C / B) – 3).
    Touchdown ratio: Y = 1000/3 * (D / B)
    Interception ratio: Z = 1250/3 * (0.095 – (E / B))
    The quarterback rating is computed by summing up the above four quantities, but rounding up or down each value so that it is at least 0 and and at most 475/12. Write a program QuarterbackRating.java that takes five command line inputs A, B, C, D, and E, and prints the quarterback rating. Use your program to compute Steve Young’s 1994 record-setting season (112.8) in which he completed 324 of 461 passes for 3,969 yards, and threw 35 touchdowns and 10 interceptions. As of 2014, the all-time single-season record is 122.5 by Aaron Rodgers in 2011.
    Decimal expansion of rational numbers. Given two integers p and q, the decimal expansion of p/q has an infinitely repeating cycle. For example, 1/33 = 0.03030303…. We use the notation 0.(03) to denote that 03 repeats indefinitely. As another example, 8639/70000 = 0.1234(142857). Write a program DecimalExpansion.java that reads in two command line integers p and q and prints the decimal expansion of p/q using the above notation. Hint: use Floyd’s rule.
    Friday the 13th. What is the maximum number of consecutive days in which no Friday the 13th occurs? Hint: The Gregorian calendar repeats itself every 400 years (146097 days) so you only need to worry about a 400 year interval.
    Solution: 426 (e.g., from 8/13/1999 to 10/13/2000).

    January 1. Is January 1 more likely to fall on a Saturday or Sunday? Write a program to determine the number of times each occurs in a 400 year interval.
    Solution: Sunday (58 times) is more likely than Saturday (56 times).

    What do the following two code fragments do?
    for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
    if (i != j) System.out.println(i + “, ” + j);

    for (int i = 0; i < N; i++)
    for (int j = 0; (i != j) && (j < N); j++)
    System.out.println(i + “, ” + j);
    Determine what value gets printed out without using a computer. Choose the correct answer from 0, 100, 101, 517, or 1000.
    int cnt = 0;
    for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
    for (int k = 0; k < 10; k++)
    if (2*i + j >= 3*k)
    cnt++;
    System.out.println(cnt);
    Rewrite CarLoan.java from Creative Exercise XYZ so that it properly handles an interest rate of 0% and avoids dividing by 0.
    Write the shortest Java program you can that takes an integer command-line argument n and prints true if (1 + 2 + … + n) 2 is equal to (13 + 23 + … + n3).
    Solution: Always print true.

    Modify Sqrt.java so that it reports an error if the user enters a negative number and works properly if the user enters zero.
    What happens if we initialize t to -x instead of x in program Sqrt.java?
    Sample standard deviation of uniform distribution. Modify Exercise 8 so that it prints the sample standard deviation in addition to the average.
    Sample standard deviation of normal distribution. that takes an integer N as a command-line argument and uses Web Exercise 1 from Section 1.2 to print N standard normal random variables, and their average value, and sample standard deviation.
    Loaded dice. [Stephen Rudich] Suppose you have three, three sided dice. A: {2, 6, 7}, B: { 1, 5, 9}, and C: {3, 4, 8}. Two players roll a die and the one with the highest value wins. Which die would you choose? Solution: A beats B with probability 5/9, B beats C with probability 5/9 and C beats A with probability 5/9. Be sure to choose second!
    Thue–Morse sequence. Write a program ThueMorse.java that reads in a command line integer n and prints the Thue–Morse sequence of order n. The first few strings are 0, 01, 0110, 01101001. Each successive string is obtained by flipping all of the bits of the previous string and concatenating the result to the end of the previous string. The sequence has many amazing properties. For example, it is a binary sequence that is cube-free: it does not contain 000, 111, 010101, or sss where s is any string. It is self-similar: if you delete every other bit, you get another Thue–Morse sequence. It arises in diverse areas of mathematics as well as chess, graphic design, weaving patterns, and music composition.
    Program Binary.java prints the binary representation of a decimal number n by casting out powers of 2. Write an alternate version Program Binary2.java that is based on the following method: Write 1 if n is odd, 0 if n is even. Divide n by 2, throwing away the remainder. Repeat until n = 0 and read the answer backwards. Use % to determine whether n is even, and use string concatenation to form the answer in reverse order.
    What does the following code fragment do?
    int digits = 0;
    do {
    digits++;
    n = n / 10;
    } while (n > 0);
    Solution: The number of bits in the binary representation of a natural number n. We use a do-while loop so that code output 1 if n = 0.

    Write a program NPerLine.java that takes an integer command-line argument n and prints the integers from 10 to 99 with n integers per line.
    Modify NPerLine.java so that it prints the integers from 1 to 1000 with n integers per line. Make the integers line up by printing the right number of spaces before an integer (e.g., three for 1-9, two for 10-99, and one for 100-999).
    Suppose a, b, and c are random number uniformly distributed between 0 and 1. What is the probability that a, b, and c form the side length of some triangle? Hint: they will form a triangle if and only if the sum of every two values is larger than the third.
    Repeat the previous question, but calculate the probability that the resulting triangle is obtuse, given that the three numbers for a triangle. Hint: the three lengths will form an obtuse triangle if and only if (i) the sum of every two values is larger than the third and (ii) the sum of the squares of every two side lengths is greater than or equal to the square of the third.
    Answer.

    What is the value of s after executing the following code?
    int M = 987654321;
    String s = “”;
    while (M != 0) {
    int digit = M % 10;
    s = s + digit;
    M = M / 10;
    }
    What is the value of i after the following confusing code is executed?
    int i = 10;
    i = i++;
    i = ++i;
    i = i++ + ++i;
    Moral: don’t write code like this.

    Formatted ISBN number. Write a program ISBN2.java that reads in a 9 digit integer from a command-line argument, computes the check digit, and prints the fully formatted ISBN number, e.g, 0-201-31452-5.
    UPC codes. The Universal Product Code (UPC) is a 12 digit code that uniquely specifies a product. The least significant digit d1(rightmost one) is a check digit which is the uniquely determined by making the following expression a multiple of 10:
    (d1 + d3 + d5 + d7 + d9 + d11) + 3 (d2 + d4 + d6 + d8 + d10 + d12)
    As an example, the check digit corresponding to 0-48500-00102 (Tropicana Pure Premium Orange Juice) is 8 since

    (8 + 0 + 0 + 0 + 5 + 4) + 3 (2 + 1 + 0 + 0 + 8 + 0) = 50
    and 50 is a multiple of 10. Write a program that reads in a 11 digit integer from a command line parameter, computes the check digit, and prints the the full UPC. Hint: use a variable of type long to store the 11 digit number.

    Write a program that reads in the wind speed (in knots) as a command line argument and prints its force according to the Beaufort scale. Use a switch statement.
    Making change. Write a program that reads in a command line integer N (number of pennies) and prints the best way (fewest number of coins) to make change using US coins (quarters, dimes, nickels, and pennies only). For example, if N = 73 then print
    2 quarters
    2 dimes
    3 pennies
    Hint: use the greedy algorithm. That is, dispense as many quarters as possible, then dimes, then nickels, and finally pennies.

    Write a program Triangle.java that takes a command-line argument N and prints an N-by-N triangular pattern like the one below.
    * * * * * *
    . * * * * *
    . . * * * *
    . . . * * *
    . . . . * *
    . . . . . *
    Write a program Ex.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) ex like the one below. Use two for loops and one if-else statement.
    * . . . . . *
    . * . . . * .
    . . * . * . .
    . . . * . . .
    . . * . * . .
    . * . . . * .
    * . . . . . *
    Write a program BowTie.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) bowtie like the one below. Use two for loops and one if-else statement.
    * . . . . . *
    * * . . . * *
    * * * . * * *
    * * * * * * *
    * * * . * * *
    * * . . . * *
    * . . . . . *
    Write a program Diamond.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) diamond like the one below.
    % java Diamond 4
    . . . . * . . . .
    . . . * * * . . .
    . . * * * * * . .
    . * * * * * * * .
    * * * * * * * * *
    . * * * * * * * .
    . . * * * * * . .
    . . . * * * . . .
    . . . . * . . . .
    Write a program Heart.java that takes a command-line argument N and prints a heart.
    What does the program Circle.java print out when N = 5?
    for (int i = -N; i <= N; i++) {
    for (int j = -N; j <= N; j++) {
    if (i*i + j*j <= N*N) System.out.print(“* “);
    else System.out.print(“. “);
    }
    System.out.println();
    }
    Seasons. Write a program Season.java that takes two command line integers M and D and prints the season corresponding to month M (1 = January, 12 = December) and day D in the northern hemisphere. Use the following table
    SEASONFROMTO
    SpringMarch 21June 20
    SummerJune 21September 22
    FallSeptember 23December 21
    WinterDecember 21March 20

    Zodiac signs. Write a program Zodiac.java that takes two command line integers M and D and prints the Zodiac sign corresponding to month M (1 = January, 12 = December) and day D. Use the following table
    SIGNFROMTO
    CapricornDecember 22January 19
    AquariusJanuary 20February 17
    PiscesFebruary 18March 19
    AriesMarch 20April 19
    TaurusApril 20May 20
    GeminiMay 21June 20
    CancerJune 21July 22
    LeoJuly 23August 22
    VirgoAugust 23September 22
    LibraSeptember 23October 22
    ScorpioOctober 23November 21
    SagittariusNovember 22December 21
    Muay Thai kickboxing. Write a program that reads in the weight of a Muay Thai kickboxer (in pounds) as a command-line argument and prints their weight class. Use a switch statement.
    CLASSFROMTO
    Flyweight0112
    Super flyweight112115
    Bantamweight115118
    Super bantamweight118122
    Featherweight122126
    Super featherweight126130
    Lightweight130135
    Super lightweight135140
    Welterweight140147
    Super welterweight147154
    Middleweight154160
    Super middleweight160167
    Light heavyweight167175
    Super light heavyweight175183
    Cruiserweight183190
    Heavyweight190220
    Super heavyweight220–
    Euler’s sum of powers conjecture. In 1769 Euler generalized Fermat’s Last Theorem and conjectured that it is impossible to find three 4th powers whose sum is a 4th power, or four 5th powers whose sum is a 5th power, etc. The conjecture was disproved in 1966 by exhaustive computer search. Disprove the conjecture by finding positive integers a, b, c, d, and e such that a5 + b5 + c5 + d5= e5. Write a program Euler.java that reads in a command line parameter N and exhaustively searches for all such solutions with a, b, c, d, and e less than or equal to N. No counterexamples are known for powers greater than 5, but you can join EulerNet, a distributed computing effort to find a counterexample for sixth powers.
    Blackjack. Write a program Blackjack.java that takes three command line integers x, y, and z representing your two blackjack cards x and y, and the dealers face-up card z, and prints the “standard strategy” for a 6 card deck in Atlantic city. Assume that x, y, and z are integers between 1 and 10, representing an ace through a face card. Report whether the player should hit, stand, or split according to these strategy tables. (When you learn about arrays, you will encounter an alternate strategy that does not involve as many if-else statements).
    Blackjack with doubling. Modify the previous exercise to allow doubling.
    Projectile motion. The following equation gives the trajectory of a ballistic missile as a function of the initial angle theta and windspeed: xxxx. Write a java program to print the (x, y) position of the missile at each time step t. Use trial and error to determine at what angle you should aim the missile if you hope to incinerate a target located 100 miles due east of your current location and at the same elevation. Assume the windspeed is 20 mph due east.
    World series. The baseball world series is a best of 7 competition, where the first team to win four games wins the World Series. Suppose the stronger team has probability p > 1/2 of winning each game. Write a program to estimate the chance that the weaker teams wins the World Series and to estimate how many games on average it will take.
    Consider the equation (9/4)^x = x^(9/4). One solution is 9/4. Can you find another one using Newton’s method?
    Sorting networks. Write a program Sort3.java with three if statements (and no loops) that reads in three integers a, b, and c from the command line and prints them out in ascending order.
    if (a > b) swap a and b
    if (a > c) swap a and c
    if (b > c) swap b and c
    Oblivious sorting network. Convince yourself that the following code fragment rearranges the integers stored in the variables A, B, C, and D so that A <= B <= C <= D.
    if (A > B) { t = A; A = B; B = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    if (C > D) { t = C; C = D; D = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    if (D > E) { t = D; D = E; E = t; }
    if (C > D) { t = C; C = D; D = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    Devise a sequence of statements that would sort 5 integers. How many if statements does your program use?
    Optimal oblivious sorting networks. Create a program that sorts four integers using only 5 if statements, and one that sorts five integers using only 9 if statements of the type above? Oblivious sorting networks are useful for implementing sorting algorithms in hardware. How can you check that your program works for all inputs?
    Solution: Sort4.java sorts 4 elements using 5 compare-exchanges. Sort5.java sorts 5 elements using 9 compare-exchanges.

    The 0-1 principle asserts that you can verify the correctness of a (deterministic) sorting algorithm by checking whether it correctly sorts an input that is a sequence of 0s and 1s. Thus, to check that Sort5.java works, you only need to test it on the 2^5 = 32 possible inputs of 0s and 1s.

    Optimal oblivious sorting (challenging). Find an optimal sorting network for 6, 7, and 8 inputs, using 12, 16, and 19 if statements of the form in the previous problem, respectively.
    Solution: Sort6.java is the solution for sorting 6 elements.

    Optimal non-oblivious sorting. Write a program that sorts 5 inputs using only 7 comparisons. Hint: First compare the first two numbers, the second two numbers, and the larger of the two groups, and label them so that a < b < d and c < d. Second, insert the remaining element e into its proper place in the chain a < b < d by first comparing against b, then either a or d depending on the outcome. Third, insert c into the proper place in the chain involving a, b, d, and e in the same manner that you inserted e (with the knowledge that c < d). This uses 3 (first step) + 2 (second step) + 2 (third step) = 7 comparisons. This method was first discovered by H. B. Demuth in 1956.
    Weather balloon. (Etter and Ingber, p. 123) Suppose that h(t) = 0.12t4 + 12t3 – 380t2 + 4100t + 220 represents the height of a weather balloon at time t (measured in hours) for the first 48 hours after its launch. Create a table of the height at time t for t = 0 to 48. What is its maximum height? Solution: t = 5.
    Will the following code fragment compile? If so, what will it do?
    int a = 10, b = 18;
    if (a = b) System.out.println(“equal”);
    else System.out.println(“not equal”);
    Solution: It uses the assignment operator = instead of the equality operator == in the conditional. In Java, the result of this statement is an integer, but the compiler expects a boolean. As a result, the program will not compile. In some languages (notably C and C++), this code fragment will set the variable a to 18 and print equal without an error.

    Gotcha 1. What does the following code fragment do?
    boolean a = false;
    if (a = true) System.out.println(“yes”);
    else System.out.println(“no”);
    Solution: it prints yes. Note that the conditional uses = instead of ==. This means that a is assigned the value true As a result, the conditional expression evaluates to true. Java is not immune to the = vs. == error described in the previous exercise. For this reason, it is much better style to use if (a) or if (!a) when testing booleans.
    Gotcha 2. What does the following code fragment do?
    int a = 17, x = 5, y = 12;
    if (x > y);
    {
    a = 13;
    x = 23;
    }
    System.out.println(a);
    Solution: Always prints 13 since there is a spurious semicolon after the if statement. Thus, the assignment statement a = 13; will be executed even though (x <= y) It is legal (but uncommon) to have a block that does not belong to a conditional statement, loop, or method.
    Gotcha 3. What does the following code fragment do?
    for (int x = 0; x < 100; x += 0.5) {
    System.out.println(x);
    }
    Solution: It goes into an infinite loop printing 0. The compound assignment statement x += 0.5 is equivalent to x = (int) (x + 0.5).
    What does the following code fragment do?
    int income = Integer.parseInt(args[0]);
    if (income >= 311950) rate = .35;
    if (income >= 174700) rate = .33;
    if (income >= 114650) rate = .28;
    if (income >= 47450) rate = .25;
    if (income >= 0) rate = .22;
    System.out.println(rate);
    It does not compile because the compile cannot guarantee that rate is initialized. Use if-else instead.
    Application of Newton’s method. Write a program BohrRadius.java that finds the radii where the probability of finding the electron in the 4s excited state of hydrogen is zero. The probability is given by: (1 – 3r/4 + r2/8 – r3/192)2 e-r/2, where r is the radius in units of the Bohr radius (0.529173E-8 cm). Use Newton’s method. By starting Newton’s method at different values of r, you can discover all three roots. Hint: use initial values of r= 0, 5, and 13. Challenge: explain what happens if you use an initial value of r = 4 or 12.
    Pepys problem. In 1693, Samuel Pepys asked Isaac Newton which was more likely: getting at least one 1 when rolling a fair die 6 times or getting at least two 1’s when rolling a fair die 12 times. Write a program Pepys.java that uses simulation to determine the correct answer.
    What is the value of the variable s after running the following loop when N = 1, 2, 3, 4, and 5.
    String s = “”;
    for (int i = 1; i <= N; i++) {
    if (i % 2 == 0) s = s + i + s;
    else s = i + s + i;
    }
    Solution: Palindrome.java.

    Body mass index. The body mass index (BMI) is the ratio of the weight of a person (in kilograms) to the square of the height (in meters). Write a program BMI.java that takes two command-line arguments, weight and height, computes the BMI, and prints the corresponding BMI category:
    Starvation: less than 15
    Anorexic: less than 17.5
    Underweight: less than 18.5
    Ideal: greater than or equal to 18.5 but less than 25
    Overweight: greater than or equal to 25 but less than 30
    Obese: greater than or equal to 30 but less than 40
    Morbidly Obese: greater than or equal to 40
    Reynolds number. The Reynolds number is the ratio if inertial forces to viscous forces and is an important quantity in fluid dynamics. Write a program that takes in 4 command-line arguments, the diameter d, the velocity v, the density rho, and the viscosity mu, and prints the Reynold’s number d * v * rho / mu (assuming all arguments are in SI units). If the Reynold’s number is less than 2000, print laminar flow, if it’s between 2000 and 4000, print transient flow, and if it’s more than 4000, print turbulent flow.
    Wind chill revisited. The wind chill formula from Exercise 1.2.14 is only valid if the wind speed is above 3MPH and below 110MPH and the temperature is below 50 degrees Fahrenheit and above -50 degrees. Modify your solution to print an error message if the user types in a value outside the allowable range.
    Point on a sphere. Write a program to print the (x, y, z) coordinates of a random point on the surface of a sphere. Use Marsaglia’ method: pick a random point (a, b) in the unit circle as in the do-while example. Then, set x = 2a sqrt(1 – a^2 – b^2), y = 2b sqrt(1 – a^2 – b^2), z = 1 – 2(a^2 + b^2).
    Powers of k. Write a program PowersOfK.java that takes an integer K as command-line argument and prints all the positive powers of K in the Java long data type. Note: the constant Long.MAX_VALUE is the value of the largest integer in long.
    Square root, revisited. Why not use the loop-continuation condition (Math.abs(t*t – c) > EPSILON) in Sqrt.java instead of Math.abs(t – c/t) > t*EPSILON)?
    Solution: Surprisingly, it can lead to inaccurate results or worse. For example, if you supply SqrtBug.java with the command-line argument 1e-50, you get 1e-50 as the answer (instead of 1e-25); if you supply 16664444, you get an infinite loop!

    What happens when you try to compile the following code fragment?
    double x;
    if (a >= 0) x = 3.14;
    if (a < 0) x = 2.71;
    System.out.println(x);
    Solution: It complains that the variable x might not have been initialized (even though we can clearly see that x will be initialized by one of the two if statements). You can avoid this problem here by using if-else.

    Last modified on October 02, 2017.

    Copyright © 2000–2018 Robert Sedgewick and Kevin Wayne. All rights reserved.

    #880346
    +1
    Gravel Pit
    Gravel Pit
    Participant

    .3 Conditionals and Loops

    In the programs that we have examined to this point, each of the statements is executed once, in the order given. Most programs are more complicated because the sequence of statements and the number of times each is executed can vary. We use the term control flow to refer to statement sequencing in a program.

    If statements. Most computations require different actions for different inputs.
    The following code fragment uses an if statement to put the smaller of two int values in x and the larger of the two values in y, by exchanging the values in the two variables if necessary.
    anatomy of an if statement
    Flip.java uses Math.random() and an if-else statement to print the results of a coin flip.
    The table below summarizes some typical situations where you might need to use an if or if-else statement.
    examples of conditionals

    While loops. Many computations are inherently repetitive. The while loop enables us to execute a group of statements many times. This enables us to express lengthy computations without writing lots of code.
    The following code fragment computes the largest power of 2 that is less than or equal to a given positive integer n.
    anatomy of a while loop
    TenHellos.java prints “Hello World” 10 times.
    PowersOfTwo.java takes an integer command-line argument n and prints all of the powers of 2 less than or equal to n.
    For loops. The for loop is an alternate Java construct that allows us even more flexibility when writing loops.
    For notation. Many loops follow the same basic scheme: initialize an index variable to some value and then use a while loop to test an exit condition involving the index variable, using the last statement in the while loop to modify the index variable. Java’s for loop is a direct way to express such loops.
    anatomy of a for loop
    Compound assignment idioms. The idiom i++ is a shorthand notation for i = i + 1.
    Scope. The scope of a variable is the part of the program that can refer to that variable by name. Generally the scope of a variable comprises the statements that follow the declaration in the same block as the declaration. For this purpose, the code in the for loop header is considered to be in the same block as the for loop body.
    Nesting. The if, while, and for statements have the same status as assignment statements or any other statements in Java; that is, we can use them wherever a statement is called for. In particular, we can use one or more of them in the body of another statement to make compound statements. To emphasize the nesting, we use indentation in the program code.
    DivisorPattern.java has a for loop whose body contains a for loop (whose body is an if-else statement) and a print statement. It prints a pattern of asterisks where the ith row has an asterisk in each position corresponding to divisors of i (the same holds true for the columns).
    MarginalTaxRate.java computes the marginal tax rate for a given income. It uses several nested if-else statements to test from among a number of mutually exclusive possibilities.
    Loop examples.
    examples of loops
    Applications. The ability to program with loops and conditionals immediately opens up the world of computation to us.
    Ruler subdivisions. RulerN.java takes an integer command-line argument n and prints the string of ruler subdivision lengths. This program illustrates one of the essential characteristics of loops—the program could hardly be simpler, but it can produce a huge amount of output.
    Harmonic numbers
    Finite sums. The computational paradigm used in PowersOfTwo.java is one that you will use frequently. It uses two variables—one as an index that controls a loop, and the other to accumulate a computational result. Program HarmonicNumber.java uses the same paradigm to evaluate the sum
    Hn=11+12+13+14+…+1n
    These numbers, which are known as the harmonic numbers, arise frequently in the analysis of algorithms.
    Newton’s method. Newton’s methodSqrt.java uses a classic iterative technique known as Newton’s method to compute the square root of a positive number x: Start with an estimate t. If t is equal to x/t (up to machine precision), then t is equal to a square root of x, so the computation is complete. If not, refine the estimate by replacing t with the average of t and x/t. Each time we perform this update, we get closer to the desired answer.
    Number conversion. Binary.java prints the binary (base 2) representation of the decimal number typed as the command-line argument. It is based on decomposing the number into a sum of powers of 2. For example, the binary representation of 106 is 11010102, which is the same as saying that 106 = 64 + 32 + 8 + 2. To compute the binary representation of n, we consider the powers of 2 less than or equal to n in decreasing order to determine which belong in the binary decomposition (and therefore correspond to a 1 bit in the binary representation).
    Gambler’s ruin. gambler’s ruin Suppose a gambler makes a series of fair $1 bets, starting with $50, and continue to play until she either goes broke or has $250. What are the chances that she will go home with $250, and how many bets might she expect to make before winning or losing? Gambler.java is a simulation that can help answer these questions. It takes three command-line arguments, the initial stake ($50), the goal amount ($250), and the number of times we want to simulate the game.
    Prime factorization. Factors.java takes an integer command-line argument n and prints its prime factorization. In contrast to many of the other programs that we have seen (which we could do in a few minutes with a calculator or pencil and paper), this computation would not be feasible without a computer.
    Other conditional and loop constructs. To be complete, we consider four more Java constructs related to conditionals and loops. They are used much less frequently than the if, while, and for statements that we’ve been working with, but it is worthwhile to be aware of them.
    Break statements. In some situations, we want to immediate exit a loop without letting it run to completion. Java provides the break statement for this purpose. Prime.java takes an integer command-line argument n and prints true if n is prime, and false otherwise. There are two different ways to leave this loop: either the break statement is executed (because n is not prime) or the loop-continuation condiQUITE THE LOLS QUITE THE LOOLLSLLSLSLLSentered at (0, 0) with radius 1.
    do-while loop
    With Math.random() we get points that are randomly distributed in the 2-by-2 square center at (0, 0). We just generate points in this region until we find one that lies inside the unit disk. We always want to generate at least one point so a do-while loop is most appropriate. We must declare x and y outside the loop since we will want to access their values after the loop terminates.

    We don’t use the following two flow control statements in this textbook, but include them here for completeness.
    Conditional operator. The conditional operator ?: is a ternary operator (three operands) that enables you to embed a conditional within an expression. The three operands are separated by the ? and : symbols. If the first operand (a boolean expression) is true, the result has the value of the second expression; otherwise it has the value of the third expression.
    int min = (x < y) ? x : y;
    Labeled break and continue statements. The break and continue statements apply to the innermost for or while loop. Sometimes we want to jump out of several levels of nested loops. Java provides the labeled break and labeled continue statements to accomplish this. Here is an example.
    Exercises
    Write a program AllEqual.java that takes three integer command-line arguments and prints equal if all three are equal, and not equal otherwise.
    Write a program RollLoadedDie.java that prints the result of rolling a loaded die such that the probability of getting a 1, 2, 3, 4, or 5 is 1/8 and the probability of getting a 6 is 3/8.
    Rewrite TenHellos.java to make a program Hellos.java that takes the number of lines to print as a command-line argument. You may assume that the argument is less than 1000. Hint: consider using i % 10 and i % 100 to determine whether to use “st”, “nd”, “rd”, or “th” for printing the ith Hello.
    Write a program FivePerLine.java that, using one for loop and one if statement, prints the integers from 1000 to 2000 with five integers per line. Hint: use the % operator.
    Write a program FunctionGrowth.java that prints a table of the values of ln n, n, n ln n, n2, n3, and 2n for n = 16, 32, 64, …, 2048. Use tabs (‘\t’ characters) to line up columns.
    What is the value of m and n after executing the following code?
    int n = 123456789;
    int m = 0;
    while (n != 0) {
    m = (10 * m) + (n % 10);
    n = n / 10;
    }
    What does the following code print out?
    int f = 0, g = 1;
    for (int i = 0; i <= 15; i++) {
    System.out.println(f);
    f = f + g;
    g = f – g;
    }
    Unlike the harmonic numbers, the sum 1/1 + 1/4 + 1/9 + 1/16 + … + 1/n2 does converge to a constant as n grows to infinity. (Indeed, the constant is π2 / 6, so this formula can be used to estimate the value of π.) Which of the following for loops computes this sum? Assume that n is an int initialized to 1000000 and sum is a double initialized to 0.
    (a) for (int i = 1; i <= n; i++)
    sum = sum + 1 / (i * i);

    (b) for (int i = 1; i <= n; i++)
    sum = sum + 1.0 / i * i;

    (c) for (int i = 1; i <= n; i++)
    sum = sum + 1.0 / (i * i);

    (d) for (int i = 1; i <= n; i++)
    sum = sum + 1 / (1.0 * i * i);
    Modify Binary.java to get a program Modify Kary.java that takes a second command-line argument K and converts the first argument to base K. Assume the base is between 2 and 16. For bases greater than 10, use the letters A through F to represent the 11th through 16th digits, respectively.
    Write a program code fragment that puts the binary representation of a positive integer n into a String variable s.
    Creative Exercises
    Ramanujan’s taxi. S. Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him in the hospital one day, Hardy remarked that the number of his taxi was 1729, a rather dull number. To which Ramanujan replied, “No, Hardy! No, Hardy! It is a very interesting number. It is the smallest number expressible as the sum of two cubes in two different ways.” Verify this claim by writing a program Ramanujan.java that takes an integer command-line argument n and prints all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways – find distinct positive integers a, b, c, and d such that a3 + b3 = c3 + d3. Use four nested for loops.
    Now, the license plate 87539319 seems like a rather dull number. Determine why it’s not.

    Checksums. The International Standard Book Number (ISBN) is a 10 digit code that uniquely specifies a book. The rightmost digit is a checksum digit which can be uniquely determined from the other 9 digits from the condition that d1 + 2d2 + 3d3 + … + 10d10 must be a multiple of 11 (here di denotes the ith digit from the right). The checksum digit d1 can be any value from 0 to 10: the ISBN convention is to use the value X to denote 10. Example: the checksum digit corresponding to 020131452 is 5 since is the only value of d1 between 0 and and 10 for which d1 + 2*2 + 3*5 + 4*4 + 5*1 + 6*3 + 7*1 + 8*0 + 9*2 + 10*0 is a multiple of 11. Write a program ISBN.java that takes a 9-digit integer as a command-line argument, computes the checksum, and prints the 10-digit ISBN number. It’s ok if you don’t print any leading 0s.
    Exponential function. Assume that x is a positive variable of type double. Write a program Exp.java that computes e^x using the Taylor series expansion
    ex=1+x+x22!+x33+x44!+…
    Trigonometric functions. Write two programs Sin.java and Cos.java that compute sin x and cos x using the Taylor series expansions
    sinx=x−x33!+x55!−x77!+…
    cosx=1−x22!+x44!−x66!+…
    Game simulation. In the game show Let’s Make a Deal, a contestant is presented with three doors. Behind one door is a valuable prize, behind the other two are gag gifts. After the contestant chooses a door, the host opens up one of the other two doors (never revealing the prize, of course). The contestant is then given the opportunity to switch to the other unopened door. Should the contestant do so? Intuitively, it might seem that the contestant’s initial choice door and the other unopened door are equally likely to contain the prize, so there would be no incentive to switch. Write a program MonteHall.java to test this intuition by simulation. Your program should take an integer command-line argument n, play the game n times using each of the two strategies (switch or don’t switch) and print the chance of success for each strategy. Or you can play the game here.
    Euler’s sum-of-powers conjecture. In 1769 Leonhard Euler formulated a generalized version of Fermat’s Last Theorem, conjecturing that at least n nth powers are needed to obtain a sum that is itself an nth power, for n > 2. Write a program Euler.java to disprove Euler’s conjecture (which stood until 1967), using a quintuply nested loop to find four positive integers whose 5th power sums to the 5th power of another positive integer. That is, find a, b, c, d, and e such that a5 + b5 + c5 + d5 = e5. Use the long data type.
    Web Exercises
    Write a program RollDie.java that generates the result of rolling a fair six-sided die (an integer between 1 and 6).
    Write a program that takes three integer command-line arguments a, b, and c and print the number of distinct values (1, 2, or 3) among a, b, and c.
    Write a program that takes five integer command-line arguments and prints the median (the third largest one).
    (hard) Now, try to compute the median of 5 elements such that when executed, it never makes more than 6 total comparisons.
    How can I create in an infinite loop with a for loop?
    Solution: for(;;) is the same as while(true).

    What’s wrong with the following loop?
    boolean done = false;
    while (done = false) {

    }
    The while loop condition uses = instead of == so it is an assignment statement (which makes done always false and the body of the loop will never be executed). It’s better to style to avoid using ==.
    boolean done = false;
    while (!done) {

    }
    What’s wrong with the following loop that is intended to compute the sum of the integers 1 through 100?
    for (int i = 1; i <= N; i++) {
    int sum = 0;
    sum = sum + i;
    }
    System.out.println(sum);
    The variable sum should be defined outside the loop. By defining it inside the loop, a new variable sum is initialized to 0 each time through the loop; also it is not even accessible outside the loop.
    Write a program Hurricane.java that that takes the wind speed (in miles per hour) as an integer command-line argument and prints whether it qualifies as a hurricane, and if so, whether it is a Category 1, 2, 3, 4, or 5 hurricane. Below is a table of the wind speeds according to the Saffir-Simpson scale.
    CategoryWind Speed (mph)
    174 – 95
    296 – 110
    3111 – 130
    4131 – 155
    5155 and above
    What is wrong with the following code fragment?
    double x = -32.2;
    boolean isPositive = (x > 0);
    if (isPositive = true) System.out.println(x + ” is positive”);
    else System.out.println(x + ” is not positive”);
    Solution: It uses the assignment operator = instead of the equality operator ==. A better solution is to write if (isPositive).

    Change/add one character so that the following program prints 20 xs. There are two different solutions.
    int i = 0, n = 20;
    for (i = 0; i < n; i–)
    System.out.print(“x”);
    Solution: Replace the i < n condition with -i < n. Replace the i– with n–. ( In C, there is a third: replace the < with a +.)
    What does the following code fragment do?
    if (x > 0);
    System.out.println(“positive”);
    Solution: always prints positive regardless of the value of x because of the extra semicolon after the if statement.

    RGB to HSB converter. Write a program RGBtoHSV.java that takes an RGB color (three integers between 0 and 255) and transforms it to an HSB color (three different integers between 0 and 255). Write a program HSVtoRGB.java that applies the inverse transformation.
    Boys and girls. A couple beginning a family decides to keep having children until they have at least one of either sex. Estimate the average number of children they will have via simulation. Also estimate the most common outcome (record the frequency counts for 2, 3, and 4 children, and also for 5 and above). Assume that the probability p of having a boy or girl is 1/2.
    What does the following program do?
    public static void main(String[] args) {
    int N = Integer.parseInt(args[0]);
    int x = 1;
    while (N >= 1) {
    System.out.println(x);
    x = 2 * x;
    N = N / 2;
    }
    }
    Solution: Prints all of the powers of 2 less than or equal to n.
    Boys and girls. Repeat the previous question, but assume the couple keeps having children until they have another child which is of the same sex as the first child. How does your answer change if p is different from 1/2?
    Surprisingly, the average number of children is 2 if p = 0 or 1, and 3 for all other values of p. But the most likely value is 2 for all values of p.

    Given two positive integers a and b, what result does the following code fragment leave in c
    c = 0;
    while (b > 0) {
    if (b % 2 == 1) c = c + a;
    b = b / 2;
    a = a + a;
    }
    Solution: a * b.

    Write a program using a loop and four conditionals to print
    12 midnight
    1am
    2am

    12 noon
    1pm

    11pm
    What does the following program print?
    public class Test {
    public static void main(String[] args) {
    if (10 > 5);
    else; {
    System.out.println(“Here”);
    };
    }
    }
    Alice tosses a fair coin until she sees two consecutive heads. Bob tosses another fair coin until he sees a head followed by a tail. Write a program to estimate the probability that Alice will make fewer tosses than Bob? Solution: 39/121.
    Rewrite DayOfWeek.java from Exercise 1.2.29 so that it prints the day of the week as Sunday, Monday, and so forth instead of an integer between 0 and 6. Use a switch statement.
    Number-to-English. Write a program to read in a command line integer between -999,999,999 and 999,999,999 and print the English equivalent. Here is an exhaustive list of words that your program should use: negative, zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand, million . Don’t use hundred, when you can use thousand, e.g., use one thousand five hundred instead of fifteen hundred. Reference.
    Gymnastics judging. A gymnast’s score is determined by a panel of 6 judges who each decide a score between 0.0 and 10.0. The final score is determined by discarding the high and low scores, and averaging the remaining 4. Write a program GymnasticsScorer.java that takes 6 real command line inputs representing the 6 scores and prints their average, after throwing out the high and low scores.
    Quarterback rating. To compare NFL quarterbacks, the NFL devised a the quarterback rating formula based on the quarterbacks number of completed passes (A), pass attempts (B), passing yards (C), touchdown passes (D), and interception (E) as follows:
    Completion ratio: W = 250/3 * ((A / B) – 0.3).
    Yards per pass: X = 25/6 * ((C / B) – 3).
    Touchdown ratio: Y = 1000/3 * (D / B)
    Interception ratio: Z = 1250/3 * (0.095 – (E / B))
    The quarterback rating is computed by summing up the above four quantities, but rounding up or down each value so that it is at least 0 and and at most 475/12. Write a program QuarterbackRating.java that takes five command line inputs A, B, C, D, and E, and prints the quarterback rating. Use your program to compute Steve Young’s 1994 record-setting season (112.8) in which he completed 324 of 461 passes for 3,969 yards, and threw 35 touchdowns and 10 interceptions. As of 2014, the all-time single-season record is 122.5 by Aaron Rodgers in 2011.
    Decimal expansion of rational numbers. Given two integers p and q, the decimal expansion of p/q has an infinitely repeating cycle. For example, 1/33 = 0.03030303…. We use the notation 0.(03) to denote that 03 repeats indefinitely. As another example, 8639/70000 = 0.1234(142857). Write a program DecimalExpansion.java that reads in two command line integers p and q and prints the decimal expansion of p/q using the above notation. Hint: use Floyd’s rule.
    Friday the 13th. What is the maximum number of consecutive days in which no Friday the 13th occurs? Hint: The Gregorian calendar repeats itself every 400 years (146097 days) so you only need to worry about a 400 year interval.
    Solution: 426 (e.g., from 8/13/1999 to 10/13/2000).

    January 1. Is January 1 more likely to fall on a Saturday or Sunday? Write a program to determine the number of times each occurs in a 400 year interval.
    Solution: Sunday (58 times) is more likely than Saturday (56 times).

    What do the following two code fragments do?
    for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
    if (i != j) System.out.println(i + “, ” + j);

    for (int i = 0; i < N; i++)
    for (int j = 0; (i != j) && (j < N); j++)
    System.out.println(i + “, ” + j);
    Determine what value gets printed out without using a computer. Choose the correct answer from 0, 100, 101, 517, or 1000.
    int cnt = 0;
    for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
    for (int k = 0; k < 10; k++)
    if (2*i + j >= 3*k)
    cnt++;
    System.out.println(cnt);
    Rewrite CarLoan.java from Creative Exercise XYZ so that it properly handles an interest rate of 0% and avoids dividing by 0.
    Write the shortest Java program you can that takes an integer command-line argument n and prints true if (1 + 2 + … + n) 2 is equal to (13 + 23 + … + n3).
    Solution: Always print true.

    Modify Sqrt.java so that it reports an error if the user enters a negative number and works properly if the user enters zero.
    What happens if we initialize t to -x instead of x in program Sqrt.java?
    Sample standard deviation of uniform distribution. Modify Exercise 8 so that it prints the sample standard deviation in addition to the average.
    Sample standard deviation of normal distribution. that takes an integer N as a command-line argument and uses Web Exercise 1 from Section 1.2 to print N standard normal random variables, and their average value, and sample standard deviation.
    Loaded dice. [Stephen Rudich] Suppose you have three, three sided dice. A: {2, 6, 7}, B: { 1, 5, 9}, and C: {3, 4, 8}. Two players roll a die and the one with the highest value wins. Which die would you choose? Solution: A beats B with probability 5/9, B beats C with probability 5/9 and C beats A with probability 5/9. Be sure to choose second!
    Thue–Morse sequence. Write a program ThueMorse.java that reads in a command line integer n and prints the Thue–Morse sequence of order n. The first few strings are 0, 01, 0110, 01101001. Each successive string is obtained by flipping all of the bits of the previous string and concatenating the result to the end of the previous string. The sequence has many amazing properties. For example, it is a binary sequence that is cube-free: it does not contain 000, 111, 010101, or sss where s is any string. It is self-similar: if you delete every other bit, you get another Thue–Morse sequence. It arises in diverse areas of mathematics as well as chess, graphic design, weaving patterns, and music composition.
    Program Binary.java prints the binary representation of a decimal number n by casting out powers of 2. Write an alternate version Program Binary2.java that is based on the following method: Write 1 if n is odd, 0 if n is even. Divide n by 2, throwing away the remainder. Repeat until n = 0 and read the answer backwards. Use % to determine whether n is even, and use string concatenation to form the answer in reverse order.
    What does the following code fragment do?
    int digits = 0;
    do {
    digits++;
    n = n / 10;
    } while (n > 0);
    Solution: The number of bits in the binary representation of a natural number n. We use a do-while loop so that code output 1 if n = 0.

    Write a program NPerLine.java that takes an integer command-line argument n and prints the integers from 10 to 99 with n integers per line.
    Modify NPerLine.java so that it prints the integers from 1 to 1000 with n integers per line. Make the integers line up by printing the right number of spaces before an integer (e.g., three for 1-9, two for 10-99, and one for 100-999).
    Suppose a, b, and c are random number uniformly distributed between 0 and 1. What is the probability that a, b, and c form the side length of some triangle? Hint: they will form a triangle if and only if the sum of every two values is larger than the third.
    Repeat the previous question, but calculate the probability that the resulting triangle is obtuse, given that the three numbers for a triangle. Hint: the three lengths will form an obtuse triangle if and only if (i) the sum of every two values is larger than the third and (ii) the sum of the squares of every two side lengths is greater than or equal to the square of the third.
    Answer.

    What is the value of s after executing the following code?
    int M = 987654321;
    String s = “”;
    while (M != 0) {
    int digit = M % 10;
    s = s + digit;
    M = M / 10;
    }
    What is the value of i after the following confusing code is executed?
    int i = 10;
    i = i++;
    i = ++i;
    i = i++ + ++i;
    Moral: don’t write code like this.

    Formatted ISBN number. Write a program ISBN2.java that reads in a 9 digit integer from a command-line argument, computes the check digit, and prints the fully formatted ISBN number, e.g, 0-201-31452-5.
    UPC codes. The Universal Product Code (UPC) is a 12 digit code that uniquely specifies a product. The least significant digit d1(rightmost one) is a check digit which is the uniquely determined by making the following expression a multiple of 10:
    (d1 + d3 + d5 + d7 + d9 + d11) + 3 (d2 + d4 + d6 + d8 + d10 + d12)
    As an example, the check digit corresponding to 0-48500-00102 (Tropicana Pure Premium Orange Juice) is 8 since

    (8 + 0 + 0 + 0 + 5 + 4) + 3 (2 + 1 + 0 + 0 + 8 + 0) = 50
    and 50 is a multiple of 10. Write a program that reads in a 11 digit integer from a command line parameter, computes the check digit, and prints the the full UPC. Hint: use a variable of type long to store the 11 digit number.

    Write a program that reads in the wind speed (in knots) as a command line argument and prints its force according to the Beaufort scale. Use a switch statement.
    Making change. Write a program that reads in a command line integer N (number of pennies) and prints the best way (fewest number of coins) to make change using US coins (quarters, dimes, nickels, and pennies only). For example, if N = 73 then print
    2 quarters
    2 dimes
    3 pennies
    Hint: use the greedy algorithm. That is, dispense as many quarters as possible, then dimes, then nickels, and finally pennies.

    Write a program Triangle.java that takes a command-line argument N and prints an N-by-N triangular pattern like the one below.
    * * * * * *
    . * * * * *
    . . * * * *
    . . . * * *
    . . . . * *
    . . . . . *
    Write a program Ex.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) ex like the one below. Use two for loops and one if-else statement.
    * . . . . . *
    . * . . . * .
    . . * . * . .
    . . . * . . .
    . . * . * . .
    . * . . . * .
    * . . . . . *
    Write a program BowTie.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) bowtie like the one below. Use two for loops and one if-else statement.
    * . . . . . *
    * * . . . * *
    * * * . * * *
    * * * * * * *
    * * * . * * *
    * * . . . * *
    * . . . . . *
    Write a program Diamond.java that takes a command-line argument N and prints a (2N + 1)-by-(2N + 1) diamond like the one below.
    % java Diamond 4
    . . . . * . . . .
    . . . * * * . . .
    . . * * * * * . .
    . * * * * * * * .
    * * * * * * * * *
    . * * * * * * * .
    . . * * * * * . .
    . . . * * * . . .
    . . . . * . . . .
    Write a program Heart.java that takes a command-line argument N and prints a heart.
    What does the program Circle.java print out when N = 5?
    for (int i = -N; i <= N; i++) {
    for (int j = -N; j <= N; j++) {
    if (i*i + j*j <= N*N) System.out.print(“* “);
    else System.out.print(“. “);
    }
    System.out.println();
    }
    Seasons. Write a program Season.java that takes two command line integers M and D and prints the season corresponding to month M (1 = January, 12 = December) and day D in the northern hemisphere. Use the following table
    SEASONFROMTO
    SpringMarch 21June 20
    SummerJune 21September 22
    FallSeptember 23December 21
    WinterDecember 21March 20

    Zodiac signs. Write a program Zodiac.java that takes two command line integers M and D and prints the Zodiac sign corresponding to month M (1 = January, 12 = December) and day D. Use the following table
    SIGNFROMTO
    CapricornDecember 22January 19
    AquariusJanuary 20February 17
    PiscesFebruary 18March 19
    AriesMarch 20April 19
    TaurusApril 20May 20
    GeminiMay 21June 20
    CancerJune 21July 22
    LeoJuly 23August 22
    VirgoAugust 23September 22
    LibraSeptember 23October 22
    ScorpioOctober 23November 21
    SagittariusNovember 22December 21
    Muay Thai kickboxing. Write a program that reads in the weight of a Muay Thai kickboxer (in pounds) as a command-line argument and prints their weight class. Use a switch statement.
    CLASSFROMTO
    Flyweight0112
    Super flyweight112115
    Bantamweight115118
    Super bantamweight118122
    Featherweight122126
    Super featherweight126130
    Lightweight130135
    Super lightweight135140
    Welterweight140147
    Super welterweight147154
    Middleweight154160
    Super middleweight160167
    Light heavyweight167175
    Super light heavyweight175183
    Cruiserweight183190
    Heavyweight190220
    Super heavyweight220-
    Euler’s sum of powers conjecture. In 1769 Euler generalized Fermat’s Last Theorem and conjectured that it is impossible to find three 4th powers whose sum is a 4th power, or four 5th powers whose sum is a 5th power, etc. The conjecture was disproved in 1966 by exhaustive computer search. Disprove the conjecture by finding positive integers a, b, c, d, and e such that a5 + b5 + c5 + d5= e5. Write a program Euler.java that reads in a command line parameter N and exhaustively searches for all such solutions with a, b, c, d, and e less than or equal to N. No counterexamples are known for powers greater than 5, but you can join EulerNet, a distributed computing effort to find a counterexample for sixth powers.
    Blackjack. Write a program Blackjack.java that takes three command line integers x, y, and z representing your two blackjack cards x and y, and the dealers face-up card z, and prints the “standard strategy” for a 6 card deck in Atlantic city. Assume that x, y, and z are integers between 1 and 10, representing an ace through a face card. Report whether the player should hit, stand, or split according to these strategy tables. (When you learn about arrays, you will encounter an alternate strategy that does not involve as many if-else statements).
    Blackjack with doubling. Modify the previous exercise to allow doubling.
    Projectile motion. The following equation gives the trajectory of a ballistic missile as a function of the initial angle theta and windspeed: xxxx. Write a java program to print the (x, y) position of the missile at each time step t. Use trial and error to determine at what angle you should aim the missile if you hope to incinerate a target located 100 miles due east of your current location and at the same elevation. Assume the windspeed is 20 mph due east.
    World series. The baseball world series is a best of 7 competition, where the first team to win four games wins the World Series. Suppose the stronger team has probability p > 1/2 of winning each game. Write a program to estimate the chance that the weaker teams wins the World Series and to estimate how many games on average it will take.
    Consider the equation (9/4)^x = x^(9/4). One solution is 9/4. Can you find another one using Newton’s method?
    Sorting networks. Write a program Sort3.java with three if statements (and no loops) that reads in three integers a, b, and c from the command line and prints them out in ascending order.
    if (a > b) swap a and b
    if (a > c) swap a and c
    if (b > c) swap b and c
    Oblivious sorting network. Convince yourself that the following code fragment rearranges the integers stored in the variables A, B, C, and D so that A <= B <= C <= D.
    if (A > B) { t = A; A = B; B = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    if (C > D) { t = C; C = D; D = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    if (D > E) { t = D; D = E; E = t; }
    if (C > D) { t = C; C = D; D = t; }
    if (B > C) { t = B; B = C; C = t; }
    if (A > B) { t = A; A = B; B = t; }
    Devise a sequence of statements that would sort 5 integers. How many if statements does your program use?
    Optimal oblivious sorting networks. Create a program that sorts four integers using only 5 if statements, and one that sorts five integers using only 9 if statements of the type above? Oblivious sorting networks are useful for implementing sorting algorithms in hardware. How can you check that your program works for all inputs?
    Solution: Sort4.java sorts 4 elements using 5 compare-exchanges. Sort5.java sorts 5 elements using 9 compare-exchanges.

    The 0-1 principle asserts that you can verify the correctness of a (deterministic) sorting algorithm by checking whether it correctly sorts an input that is a sequence of 0s and 1s. Thus, to check that Sort5.java works, you only need to test it on the 2^5 = 32 possible inputs of 0s and 1s.

    Optimal oblivious sorting (challenging). Find an optimal sorting network for 6, 7, and 8 inputs, using 12, 16, and 19 if statements of the form in the previous problem, respectively.
    Solution: Sort6.java is the solution for sorting 6 elements.

    Optimal non-oblivious sorting. Write a program that sorts 5 inputs using only 7 comparisons. Hint: First compare the first two numbers, the second two numbers, and the larger of the two groups, and label them so that a < b < d and c < d. Second, insert the remaining element e into its proper place in the chain a < b < d by first comparing against b, then either a or d depending on the outcome. Third, insert c into the proper place in the chain involving a, b, d, and e in the same manner that you inserted e (with the knowledge that c < d). This uses 3 (first step) + 2 (second step) + 2 (third step) = 7 comparisons. This method was first discovered by H. B. Demuth in 1956.
    Weather balloon. (Etter and Ingber, p. 123) Suppose that h(t) = 0.12t4 + 12t3 – 380t2 + 4100t + 220 represents the height of a weather balloon at time t (measured in hours) for the first 48 hours after its launch. Create a table of the height at time t for t = 0 to 48. What is its maximum height? Solution: t = 5.
    Will the following code fragment compile? If so, what will it do?
    int a = 10, b = 18;
    if (a = b) System.out.println(“equal”);
    else System.out.println(“not equal”);
    Solution: It uses the assignment operator = instead of the equality operator == in the conditional. In Java, the result of this statement is an integer, but the compiler expects a boolean. As a result, the program will not compile. In some languages (notably C and C++), this code fragment will set the variable a to 18 and print equal without an error.

    Gotcha 1. What does the following code fragment do?
    boolean a = false;
    if (a = true) System.out.println(“yes”);
    else System.out.println(“no”);
    Solution: it prints yes. Note that the conditional uses = instead of ==. This means that a is assigned the value true As a result, the conditional expression evaluates to true. Java is not immune to the = vs. == error described in the previous exercise. For this reason, it is much better style to use if (a) or if (!a) when testing booleans.
    Gotcha 2. What does the following code fragment do?
    int a = 17, x = 5, y = 12;
    if (x > y);
    {
    a = 13;
    x = 23;
    }
    System.out.println(a);
    Solution: Always prints 13 since there is a spurious semicolon after the if statement. Thus, the assignment statement a = 13; will be executed even though (x <= y) It is legal (but uncommon) to have a block that does not belong to a conditional statement, loop, or method.
    Gotcha 3. What does the following code fragment do?
    for (int x = 0; x < 100; x += 0.5) {
    System.out.println(x);
    }
    Solution: It goes into an infinite loop printing 0. The compound assignment statement x += 0.5 is equivalent to x = (int) (x + 0.5).
    What does the following code fragment do?
    int income = Integer.parseInt(args[0]);
    if (income >= 311950) rate = .35;
    if (income >= 174700) rate = .33;
    if (income >= 114650) rate = .28;
    if (income >= 47450) rate = .25;
    if (income >= 0) rate = .22;
    System.out.println(rate);
    It does not compile because the compile cannot guarantee that rate is initialized. Use if-else instead.
    Application of Newton’s method. Write a program BohrRadius.java that finds the radii where the probability of finding the electron in the 4s excited state of hydrogen is zero. The probability is given by: (1 – 3r/4 + r2/8 – r3/192)2 e-r/2, where r is the radius in units of the Bohr radius (0.529173E-8 cm). Use Newton’s method. By starting Newton’s method at different values of r, you can discover all three roots. Hint: use initial values of r= 0, 5, and 13. Challenge: explain what happens if you use an initial value of r = 4 or 12.
    Pepys problem. In 1693, Samuel Pepys asked Isaac Newton which was more likely: getting at least one 1 when rolling a fair die 6 times or getting at least two 1’s when rolling a fair die 12 times. Write a program Pepys.java that uses simulation to determine the correct answer.
    What is the value of the variable s after running the following loop when N = 1, 2, 3, 4, and 5.
    String s = “”;
    for (int i = 1; i <= N; i++) {
    if (i % 2 == 0) s = s + i + s;
    else s = i + s + i;
    }
    Solution: Palindrome.java.

    Body mass index. The body mass index (BMI) is the ratio of the weight of a person (in kilograms) to the square of the height (in meters). Write a program BMI.java that takes two command-line arguments, weight and height, computes the BMI, and prints the corresponding BMI category:
    Starvation: less than 15
    Anorexic: less than 17.5
    Underweight: less than 18.5
    Ideal: greater than or equal to 18.5 but less than 25
    Overweight: greater than or equal to 25 but less than 30
    Obese: greater than or equal to 30 but less than 40
    Morbidly Obese: greater than or equal to 40
    Reynolds number. The Reynolds number is the ratio if inertial forces to viscous forces and is an important quantity in fluid dynamics. Write a program that takes in 4 command-line arguments, the diameter d, the velocity v, the density rho, and the viscosity mu, and prints the Reynold’s number d * v * rho / mu (assuming all arguments are in SI units). If the Reynold’s number is less than 2000, print laminar flow, if it’s between 2000 and 4000, print transient flow, and if it’s more than 4000, print turbulent flow.
    Wind chill revisited. The wind chill formula from Exercise 1.2.14 is only valid if the wind speed is above 3MPH and below 110MPH and the temperature is below 50 degrees Fahrenheit and above -50 degrees. Modify your solution to print an error message if the user types in a value outside the allowable range.
    Point on a sphere. Write a program to print the (x, y, z) coordinates of a random point on the surface of a sphere. Use Marsaglia’ method: pick a random point (a, b) in the unit circle as in the do-while example. Then, set x = 2a sqrt(1 – a^2 – b^2), y = 2b sqrt(1 – a^2 – b^2), z = 1 – 2(a^2 + b^2).
    Powers of k. Write a program PowersOfK.java that takes an integer K as command-line argument and prints all the positive powers of K in the Java long data type. Note: the constant Long.MAX_VALUE is the value of the largest integer in long.
    Square root, revisited. Why not use the loop-continuation condition (Math.abs(t*t – c) > EPSILON) in Sqrt.java instead of Math.abs(t – c/t) > t*EPSILON)?
    Solution: Surprisingly, it can lead to inaccurate results or worse. For example, if you supply SqrtBug.java with the command-line argument 1e-50, you get 1e-50 as the answer (instead of 1e-25); if you supply 16664444, you get an infinite loop!

    What happens when you try to compile the following code fragment?
    double x;
    if (a >= 0) x = 3.14;
    if (a < 0) x = 2.71;
    System.out.println(x);
    Solution: It complains that the variable x might not have been initialized (even though we can clearly see that x will be initialized by one of the two if statements). You can avoid this problem here by using if-else.

    Last modified on October 02, 2017.

    Copyright © 2000–2018 Robert Sedgewick and Kevin Wayne. All rights reserved.

    #880347
    Gravel Pit
    Gravel Pit
    Participant
    #880351
    Gravel Pit
    Gravel Pit
    Participant

    WHO CLASSIFICATION OF HEAD AND NECK TUMOURS 1
    C00-C06, C09-C10, C14 – Lip, Oral Cavity and Oropharynx:

    Malignant epithelial tumors
    Benign epithelial tumors
    Salivary gland tumors
    Soft tissue tumors
    Haematolymphoid tumors

    Malignant epithelial tumors
    8070/3 Squamous cell carcinoma, NOS
    8051/3 Verrucous carcinoma, NOS
    8083/3 Basaloid squamous cell carcinoma
    8052/3 Papillary squamous cell carcinoma
    8074/3 Squamous cell carcinoma, spindle cell
    8075/3 Squamous cell carcinoma, adenoid
    8560/3 Adenosquamous carcinoma
    8082/3 Lymphoepithelial carcinoma
    8082/3 Schmincke tumor

    Benign epithelial tumors
    8050/0 Papilloma, NOS
    9580/0 Granular cell tumor, NOS

    Salivary gland tumors
    Salivary gland carcinomas
    8550/3 Acinar cell carcinoma
    8430/3 Mucoepidermoid carcinoma
    8200/3 Adenoid cystic carcinoma
    8200/3 Bronchial adenoma, cylindroid
    8525/3 Polymorphous low grade adenocarcinoma
    8147/3 Basal cell adenocarcinoma
    8562/3 Epithelial-myoepithelial carcinoma
    8310/3 Clear cell adenocarcinoma, NOS
    8310/3 Clear cell adenocarcinoma, mesonephroid
    8450/3 Papillary cystadenocarcinoma, NOS
    8480/3 Mucinous adenocarcinoma
    8480/3 Pseudomyxoma peritonei with unknown primary site
    8290/3 Oxyphilic adenocarcinoma
    8290/3 Hurthle cell carcinoma
    8290/3 Hurthle cell adenocarcinoma
    8290/3 Follicular carcinoma, oxyphilic cell
    8500/3 Infiltrating duct carcinoma, NOS
    8982/3 Malignant myoepithelioma
    8941/3 Carcinoma in pleomorphic adenoma

    Salivary gland adenomas
    8940/0 Pleomorphic adenoma
    8940/0 Chondroid syringoma
    8982/0 Myoepithelioma
    8147/0 Basal cell adenoma
    8149/0 Canalicular adenoma
    8503/0 Intraductal papilloma
    8440/0 Cystadenoma, NOS

    Soft tissue tumors
    9140/3 Kaposi sarcoma
    9170/0 Lymphangioma, NOS

    Haematolymphoid tumors
    9673/3 Mantle cell lymphoma
    9690/3 Follicular lymphoma, NOS
    9687/3 Burkitt lymphoma, NOS
    9687/3 Burkitt-like lymphoma
    9734/3 Plasmacytoma, extramedullary
    9930/3 Myeloid sarcoma
    9758/3 Follicular dendritic cell sarcoma
    9758/3 Follicular dendritic cell tumor

    8720/3 Malignant melanoma, NOS

    IARC, 150 Cours Albert Thomas, 69372 Lyon CEDEX 08, France – Tel: +33 (0)4 72 73 84 85
    © IARC 2018 – All Rights Reserved.
    9673/3 MANTLE CELL LYMPHOMA

    Synonyms
    Mantle zone lymphoma
    Malignant lymphoma, lymphocytic, intermediate differentiation, diffuse
    Malignant lymphoma, centrocytic
    Malignant lymphomatous polyposis

    Definitions
    Small intestine
    ICD-O-3 topography code:C17
    ICD10:C83.1

    Mantle cell lymphoma (MCL) is an aggressive, usually diffuse non-Hodgkin lymphoma composed of monomorphic small to medium sized B-lymphocytes (centrocytes). The t(11;14)(q13;q32) translocation causes an overexpression of cyclin D1 (CCND1), is present in almost all cases and considered the primary genetic event 1 . MCL manisfests preferentially in middle-aged to older male patients with advanced stage disease with lymphadenopathy, hepatosplenomegaly, and bone marrow involvement. The gastrointestinal tract is the most commonly affected extranodal site, occasionally as lymphomatous polyposis.

    Tumours of haematopoietic and lymphoid tissues
    ICD-O-3 topography code:C42 and C77
    ICD10:C83.1

    /span>antle cell lymphoma (MCL) is a B-cell neoplasm generally composed of mono?morphic small to medium-sized lymphoid cells with irregular nuclear contours and a CCND1 translocation 2 3 4 5 6 7 8 . Neoplastic trans?formed cells (centroblasts), paraimmuno?blasts and proliferation centres are absent.

    >

    Lip, Oral Cavity and Oropharynx
    ICD-O-3 topography code:C00-C06, C09-C10, C14
    ICD10:C83.1

    Mantle cell lymphoma (MCL) is an aggressive, usually diffuse non-Hodgkin lymphoma composed of monomorphic small to medium sized B-lymphocytes (centrocytes). The t(11;14)(q13;q32) translocation causes an overexpression of cyclin D1 (CCND1), is present in almost all cases and considered the primary genetic event 10 .
    MCL manisfests preferentially in middle-aged to older male patients with advanced stage disease with lymphadenopathy, hepatosplenomegaly, and bone marrow involvement. The gastrointestinal tract is the most commonly affected extranodal site, occasionally as
    lymphomatous polyposis.

    Colon and rectum
    ICD-O-3 topography code:C18-C20
    ICD10:C83.1

    Mantle cell lymphoma (MCL) is an aggressive, usually diffuse non-Hodgkin lymphoma composed of monomorphic small to medium sized B-lymphocytes (centrocytes). The t(11;14)(q13;q32) translocation causes an overexpression of cyclin D1 (CCND1), is present in almost all cases and considered the primary genetic event 11 . MCL manisfests preferentially in middle-aged to older male patients with advanced stage disease with lymphadenopathy, hepatosplenomegaly, and bone marrow involvement. The gastrointestinal tract is the most commonly affected extranodal site, occasionally as lymphomatous polyposis.

    Stomach
    ICD-O-3 topography code:C16
    ICD10:C83.1

    Mantle cell lymphoma (MCL) is an aggressive, usually diffuse non-Hodgkin lymphoma composed of monomorphic small to medium sized B-lymphocytes (centrocytes). The t(11;14)(q13;q32) translocation causes an overexpression of cyclin D1 (CCND1), is present in almost all cases and considered the primary genetic event 12 .
    MCL manifests preferentially in middle-aged to older male patients with advanced stage disease with lymphadenopathy, hepatosplenomegaly, and bone marrow involvement. The gastrointestinal tract is the most commonly affected extranodal site, occasionally as lymphomatous polyposis.

    Skin
    ICD-O-3 topography code:C44
    ICD10:C83.1

    Mantle cell lymphoma (MCL) is an aggressive, usually diffuse non-Hodgkin lymphoma composed of monomorphic small to medium sized B-lymphocytes (centrocytes). The t(11;14)(q13;q32) translocation causes an overexpression of cyclin D1 (CCND1), is present in almost all cases and considered the primary genetic event 13 .
    MCL manisfests preferentially in middle-aged to older male patients with advanced stage disease with lymphadenopathy, hepatosplenomegaly, and bone marrow involvement. The gastrointestinal tract is the most commonly affected extranodal site, occasionally as
    lymphomatous polyposis.

    IARC, 150 Cours Albert Thomas, 69372 Lyon CEDEX 08, France – Tel: +33 (0)4 72 73 84 85
    © IARC 2018 – All Rights Reserved.

    #880353
    Gravel Pit
    Gravel Pit
    Participant

    The southern study area in the Xishuangbanna prefecture of China’s Yunnan Province is located
    between 22°00’N–23°50’00″N and 100°00’12″E–102°00’E and covers about 50,000 ha (Figure 1). It
    belongs to the lower catchment of the Lancang River. Xishuangbanna is home to the richest biological
    and ethnic diversity (i.e., Thai, Lahu, Jinuo, and Jingpo people) in China. The maximum altitude is
    about 2,000 m. The climate of the region is strongly seasonal. The monthly average temperature ranges
    between 16.4°C and 22.0 °C. Between May and October the South-West Monsoon air masses brings
    about 80% of annual rainfall, whereas the dry and cold air of the Southern edges of the jet stream
    dominates the weather pattern between November and April. Annual rainfall varies between 1,200 mm
    in the Lancang valley and 1,900 mm at altitudes above 1,500 m.
    Remote Sens. 2014, 6 1030
    2.2. Software
    Canoco 4.5 was used to perform ordination. ArcView 3.2 and ArcGIS 9.1 were used to calculate
    topographic attributes and to perform ordinary kriging. Artificial Neural Networks (ANN)
    classification was conducted with LNNS, a neural network simulation program developed at the
    Laboratory of Forest Management and Spatial Information Techniques (FORSIT), Ghent University,
    Belgium. LNNS is freely available at http://dfwm.ugent.be/forsit [55]. Idrisi Andes was used to assess
    accuracy comparison between different classification strategies.
    2.3. Data
    2.3.1. Image Data
    Each study area is covered by a 30 m resolution Landsat Thematic Mapper 5 (TM) image (Table 1).
    The available Landsat images are third level products of the China Remote Sensing Satellite Ground
    Station (http://www.rsgs.ac.cn/English/Standard%20Product.htm). Basic radiometric and geometric
    preprocessing was done by the image provider. Gitas and Devereux (2006) [56] mentioned that
    topographic correction should be regarded as an essential el

    #880354
    Sandals
    Sandals
    Participant
    4253

    From the horses mouth:

    #880355
    John Doe
    John Doe
    Participant
    743

    Satellite Data CodesSatellite Data Codes are used by telemetry stations, forecast centers and others to encode solar geophysical data obtained from satellite-based sensors.USXRA CodesSolar x-ray events..
    Example:
    Definition of symbols:
    USXRA comes from Solar X-RAy events
    I I I I I = station indicator
    Y = last digit of yearMM = month of year, 01 = January, 02 = February, etc. DD = UT day of month
    SS = satellite06 = GOES-607 = GOES-708 = GOES-809 = GOES-9E = energy range1 = .1-.8 nmNN = number of events
    0 = indicates that the begin time of the event followsHHmm = UT hour and minute of beginning of event
    0 = indicates that the maximum time of the event followsHHmm = UT hour and minute of maximum for event
    0 = indicates that the the end time of the event followsHHmm = UT hour and minute of end time of event
    Maximum Flux:Q = qualifier0 = uncertain data1 = certain dataab = x-ray flux in Wm-1 where ab = a.bS = sign of the exponent to apply to a.b0 = positive1 = negativep = power of ten to apply to a.bNote: abSp reported as 4192 would equal 4.1 x 10-1Wm-1
    Note: / is to be used for data not available.
    Integrated flux (start thru end):9 = qualifierab x-ray integrated flux in Jm-1 where ab = a.bS = sign of the exponent to apply to a.b0 = positive1 = negativep = power of ten to apply to a.bNote: abSp reported as 5692 would equal 5.6 x 10-1Wm-1
    Note: / is to be used for data not available.
    Home | Site Map | Contact Us | Privacy Policy | Help
    ISESMessage from the DirectorThe History of ISESWhat Do We DoConstitutionOrganizational StructureLogo
    MembersSpace Weather NowSpace Weather EffectsSatellitesAviationsNavigationsPower GridsCommunicationsExamples
    URSIgram CodesGeophysical Data CodesAlerts, Analasys & Forecasts CodesRadio Data CodesOptical Data CodesSatellite Data CodesSatellite Ionospheric Data CodesRWC and Specialized Codes

    Uhh..this is not an argument…and these satellite codes prove what? That satellites have a framework of language that exist through other frameworks of languages (numbers and English alphabet)? It just proves my point.

    #880357
    Gravel Pit
    Gravel Pit
    Participant

    Some people know what this is. I will make it my new hobby. MEOW! LOL

    Encrypted GPS

    GPS was developed by the Defense Department primarily for military purposes. And even though it’s been estimated that there are ten times as many civilian receivers as military ones the system still has considerable military significance.

    To that end the military maintains exclusive access to the more accurate “P-code” pseudo random code. It’s ten times the frequency of the civilian C/A code (and so potentially much more accurate) and much harder to jam. When it’s encrypted it’s called “Y-code” and only military receivers with the encryption key can receive it. Because this code is modulated on two carriers, sophisticated games can be played with the frequencies to help eliminate errors caused by the atmosphere.

    #880359
    Gravel Pit
    Gravel Pit
    Participant
    #880360
    John Doe
    John Doe
    Participant
    743

    Its a shot across the bow you f~~~ing s~~~christ bitch. DO not f~~~ with me

    And the schizophrenic projection occurs again.

    Go ahead and post as much as you want, a shot across the bow is just another way of rationalizing the fact you missed the point.

    All the biological examples are merely classifications of specific parts, with the parts existing relative and through other parts (such as the heart exists through the body while existing through the framework of veins and muscles with veins and muscles existing through the heart). One framework is composed of a another.

    Relative to sports they are strictly classifications of weight class where boxing exists through various weight class (which change relative to time and circumstance) and these weight classes as frameworks are effectively nothing without the framework of boxing as a set of rules.

    Relative to computer languages they are composed of various fields of mathematics, such as type theory or lambda calculus, while the languages themselves change over time relative to not just break through in mathematics and logic (or even physics with quantum computing) but standard language as well. They are all interlinked frameworks with a change in one framework changing in another.

    Geographic positions change with time as well as the boundaries due to socio political change.

    And so on and so forth. Thw argument is universal and infinite and applies to all phenomenon in infinite variation.

    #880362
    Gravel Pit
    Gravel Pit
    Participant

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    /****************************************************************/
    /* */
    /* ********* ** ** ******* ********* ** ** */
    /* ********* **** ** ******* ********* ** ** */
    /* ** ** ** ** ** ** ** ** ** */
    /* ** ** ** ** ** ** ** **** */
    /* ********* ** ** ** ** ** ** ** */
    /* ********* ** ** ** ** ** ** ** */
    /* ** ** ** ** ** ** ** ** */
    /* ** ** ** ** ** ** ** ** ** */
    /* ** ** ** ** ** ** ** ** ** */
    /* ********* ** **** ** ** ********* ** */
    /* ********* ** *** ***** ********* ** */
    /* */
    /****************************************************************/

    /********************************************************************************************************/
    /* Programme Realiser par mr Saifeddine Maatoug */
    /* le 10/03/2004 */
    /* Il s’agit d’un proget d’algorithmique dans l’ecole E.S.T.I */
    /********************************************************************************************************/

    #include “stdio.h”

    #include “conio.h”

    #define n 100

    #define nb_max 12

    typedef struct

    {

    char name[20];

    char prenom[20];

    int niveau;

    char sexe[1];

    int nb_m;

    int cin;

    int age;

    }etudianttype;

    typedef struct

    {

    char matiere[20];

    float note;

    int coef;

    }tmatiere;

    typedef struct

    {

    tmatiere t[nb_max];

    }ttmatiere;

    /************************************************************************************************************/

    /************************************************************************************************************/

    /*******************************/

    /* fonction moyenne eleve i */

    /*******************************/

    float moyenne(int m);

    {
    float r,sc,sm;

    for(i=0;i<etudiant[m].nb_m;i++)
    {
    sm=((tttmatiere[m].t.note)*(tttmatiere[m].t.coef)) +sm;
    sc=tttmatiere[m].t.coef+sc;
    }

    return(sm/sc);

    }
    /* fin fonction moyenne */

    /***********************************************************************************************************/

    /*******************************/
    /* fonction classement eleve i */
    /*******************************/

    int classement(int c);
    {
    int r=all;
    for(i=0;i<all;i++)
    {
    if (moyenne(i)>moyenne(c))
    {
    r–;
    }
    return(r);

    }
    /* fin fonction classement */

    /***********************************************************************************************************/

    /***********************************/
    /* procedure clear screen */
    /***********************************/

    void clrscr()
    {
    int i,n=15;

    for(i=0;i<n;i++)
    {
    printf(“\n”);
    printf(“\n”);

    }
    } /* fin procedure clear screen */

    /***********************************************************************************************************/

    /*************************************************************************************/
    /*procedure annulation des chaines de caracters [(.) ==> est pris comme valeur nulle]*/
    /*************************************************************************************/

    void vidage(int k)
    {
    void main();
    int c,u;

    etudiant[k].cin=0;
    etudiant[k].niveau=0;
    etudiant[k].sexe[1]=’.’;
    etudiant[k].nb_m=0;

    for(c=0;c<20;c++)
    {
    etudiant[k].name[c]=’.’;
    etudiant[k].prenom[c]=’.’;
    }
    for(u=0;u<nb_max;u++)
    {
    tttmatiere[k].t.matiere=’.’;
    tttmatiere[k].t.note=0;
    tttmatiere[k].t.coef=0;
    }

    }
    /* fin procedure annulation */

    /************************************************************************************************************/

    /************************************************/
    /* procedure affichage d’un etudiant par besoin */
    /************************************************/

    void affichage(int i,int all)
    {
    void main();
    int j,c,k=0;
    /*affiche nom*/

    clrscr();
    printf(“\nNom: “);
    for(c=0;c<20;c++)
    {
    if (etudiant.name[c]==’.’){break;} // eof pour nom
    printf(“%c”,(etudiant.name[c]));
    }
    /*affiche prénom*/
    printf(“\nPrenom: “);
    for(c=0;c<20;c++)
    {
    if (etudiant.prenom[c]==’.’){break;} // eof pour prénom
    printf(“%c”,(etudiant.prenom[c]));
    }
    /* affiche sexe*/
    printf(“\nSexe: %c”,etudiant.sexe[1]);//fin sexe
    /*affiche Numero carte identite */
    printf(“\nNumeor carte identite: %i\n”,etudiant.cin);// fin C.I.N
    /*affiche age*/
    printf(“age :%i”,etudiant.age);
    /* boucle matieres */
    printf(“cette etudiant etuide %i matieres “,etudiant.nb_m); //combient de matiere etudie cette etudiant
    for(c=0;c<nb_m;c++)
    if (k!=0)/*matiere afficheé donc on affiche note */{printf(“: %0.3f\n”,tttmatiere.note); // note de la matiere c apres affichage matiere
    {
    for(j=0;j<20;j++)
    {
    k++; // valeur pour savoire es la matiere est afficheé
    if(tttmatiere.t[c].matiere[j]==’.’){break;} // eof pour nom matiere
    printf(“%c”,tttmatiere.t[c].matiere[j]);
    }

    }
    printf(“\nMoyenne :%0.3f”,moyenne(i));
    printf(“\nClassement : %i”,classement(i));
    printf(“pour revenir au menu principal appuiez (y)”);if(getch()==’y’|’Y’){main();} // condition pour revenir au menu princiapl

    }
    /* fin procedure affichage*/

    /************************************************************************************************************/

    /************************************************/
    /* Procedure saisie d’un nouveau etudiant */
    /************************************************/

    void saisie(int i,int all)

    {
    void main();
    vidage(i);
    int c;
    /* saisie nom */
    printf(“\nDonnez Nom –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&etudiant.name[0],&etudiant.name[1],&etudiant.name[2],&etudiant.name[3],&etudiant.name[4],&etudiant.name[5],&etudiant.name[6],&etudiant.name[7],&etudiant.name[8],&etudiant.name[9],&etudiant.name[10],&etudiant.name[11],&etudiant.name[12],&etudiant.name[13],&etudiant.name[14]); // saisie nom
    /* fin saisie nom */
    printf(“\nDonnez Prenom –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&etudiant.prenom[0],&etudiant.prenom[1],&etudiant.prenom[2],&etudiant.prenom[3],&etudiant.prenom[4],&etudiant.prenom[5],&etudiant.prenom[6],&etudiant.prenom[7],&etudiant.prenom[8],&etudiant.prenom[9],&etudiant.prenom[10],&etudiant.prenom[11],&etudiant.prenom[12],&etudiant.prenom[13],&etudiant.prenom[14]);// saisie prenom
    /* fin saisie prenom */
    printf(“\nDonnez N:C.I.N –S.V.P–\n\01”);
    scanf(“%i”,&etudiant.cin); // saisie numero carte identite
    while(etudiant.sexe[1]!=’M’|’F’) // controle sexe etudiant(e)
    {
    printf(“\nDonnez sexe (M/F)\n\01”); //saisie sexe etudiant(e)
    scanf(“%c”,&etudiant.sexe[1]);
    }
    printf(“\nDonnez nombre de matiere etudieé par cette eleve\n\01”); //saisie nombre de matiere par etudiant
    scanf(“%i”,&etudiant.nb_m);
    for(c=0;c<etudiant.nb_m;c++)
    {
    printf(“\nDonnez Nom matiere: %i –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”,c);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&tttmatiere.t[c].matiere[0],&tttmatiere.t[c].matiere[1],&tttmatiere.t[c].matiere[2],&tttmatiere.t[c].matiere[3],&tttmatiere.t[c].matiere[4],&tttmatiere.t[c].matiere[5],&tttmatiere.t[c].matiere[6],&tttmatiere.t[c].matiere[7],&tttmatiere.t[c].matiere[8],&tttmatiere.t[c].matiere[9],&tttmatiere.t[c].matiere[10],&tttmatiere.t[c].matiere[11],&tttmatiere.t[c].matiere[12],&tttmatiere.t[c].matiere[13],&tttmatiere.t[c].matiere[14]); // saisie Nom matiere

    while(tttmatiere.t[c].note<0)
    {printf(“\nDonnez ca note\n\01”);scanf(“%f”,&tttmatiere.t[c].note);} // saisie note matiere de l’etudiant (i) matiere (c)
    while(tttmatiere.t[c].coef<0)
    {printf(“\nDonnez son coeficient\n\01”);scanf(“%i”,&tttmatiere.t[c].coef);} // saisie coef matiere (c) de l’etudiant (i)

    }
    while(etudiant.age<=0)
    {
    printf(“\ndonnez age etudiant\n”);
    scanf(“%i”,&etudiant.age);
    }

    while((c>2)||(c<=0))
    {
    printf(“\n\tDonnez votre choix \n”);
    printf(“1-nouveau eleve\n”);
    printf(“2-revenir au menu principal\n”)
    printf(“\01”);
    scanf(“%i”,&c);
    }
    clrscr();
    if(c==1){saisie(all);}
    if(c==2){main();}
    }

    /* fin procedure saisie */

    /***********************************************************************************************************/

    /**************************************/
    /* procedure Recherche */
    /**************************************/
    void recherche(int all)

    {
    void main();

    char ch_nom[15],ch_prenom[15];
    int c,chi,ch_cin;

    clrscr(); // effacer l’ecran

    printf(“\nDonnez votre choix S.V.P \n”);
    printf(“1-Nom\n”);
    printf(“2-Prenom\n”);
    print(“3-C.I.N\n”);

    scanf(“%i”,&chi); //saisie de choix 1 . 2 . 3

    switch(chi) // selon choix faire
    {
    case 1: { //debut choix 1

    printf(“\nDonnez Nom a RECHERCHER –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&ch_name[0],&ch_name[1],&ch_name[2],&ch_name[3],&ch_name[4],&ch_name[5],&ch_name[6],&ch_name[7],&ch_name[8],&ch_name[9],&ch_name[10],&ch_name[11],&ch_name[12],&ch_name[13],&ch_name[14]); // saisie nom a rechercher
    for(chi=0;chi<all;chi++)
    {
    trc=0;
    for(c=0;c<15;c++) //boucle recherche nom
    {
    if (etudiant[chi].name[c]==ch_name[c]){trc++;} // boucle recherche caractere par caractere
    }
    if (trc==15){trc=chi;break;}
    else{trc=0;}
    break; // pour le case 1
    }
    } //fin choix 1

    case 2: { //debut choix 2

    printf(“\nDonnez Prenom a RECHERCHER –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&ch_prenom[0],&ch_prenom[1],&ch_prenom[2],&ch_prenom[3],&ch_prenom[4],&ch_prenom[5],&ch_prenom[6],&ch_prenom[7],&ch_prenom[8],&ch_prenom[9],&ch_prenom[10],&ch_prenom[11],&ch_prenom[12],&ch_prenom[13],&ch_prenom[14]); // saisie prenom a rechercher
    for(chi=0;chi<all;chi++)
    { trc=0;
    for(c=0;c<15;c++) // boucle recherche prenom
    {
    if (etudiant[chi].prenom[c]==ch_prenom[c]){trc++;} //recherche caractere par caratere
    }
    if (trc==15){trc=chi;break;}
    else{trc=0;}
    break; // pour le case 2
    }
    } //fin choix 2

    case 3: { // choix 3
    printf(“\nDonnez Numero C.I.N a RECHERCHER \n”);
    scanf(“%i”,&ch_cin); //saisie cin a rechercher
    for(chi=0;chi<all;c++)
    {
    if(etudiant[c].cin==ch_cin){trc=c;break;}
    else {trc=0;}
    }
    break;// pour le case 3
    } // fin choix 3
    default:{printf(“le choix n’est pas valide”);getch();recherche(all);}break;
    }
    if (trc!=0)
    { //condition pour un etudiant existant
    printf(“\n—-Etudiant existant—\n “);
    printf(“Entrez votre choix\n”);
    printf(“1-Continuer ou Retour au menu\n”);
    printf(“2-afficher Fiche Etudiant”);
    printf(“3-Rechercher un autre Etudiant\n”);
    scanf(“%i”,&c);
    clrscr(); // effacer l’ecran
    switch (c)
    {

    case 1:break;
    case 2: affichage(trc,all);break;
    case 3:recherche(all);break;

    }
    }
    else {
    printf(“\nje ne peux rien confirmer car \nl’eleve ne se trouve pas aparament dans la liste\n”);
    printf(“Entrez votre choix\n”);
    printf(“1-Retour au menu\n”);
    printf(“2-Rechercher un autre Etudiant\n”);
    scanf(“%i”,&c);
    switch(c)
    {
    case 1:main();break;
    case 2:recherche(all);break;

    }
    }
    }

    /* fin procedure recherche */

    /************************************************************************************************************/

    /**************************/
    /* procedure modification */
    /**************************/

    void modif(int md)
    {

    void main();
    int c;
    clrscr();
    printf(“\nEntrez votre choix\n”);
    printf(“1-modifier Nom\n”);
    printf(“2-modifier prenom\n”);
    printf(“3-modifier C.I.N\n”);
    printf(“4-modifier sexe\n”);
    printf(“5-modifier niveau\n”);
    printf(“6-modifier age\n”);
    scanf(“%i”,&c);
    switch(c)
    {

    case 1:{ // modifier nom

    printf(“\nDonnez le nouveau Nom –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&etudiant[md].name[0],&etudiant[md].name[1],&etudiant[md].name[2],&etudiant[md].name[3],&etudiant[md].name[4],&etudiant[md].name[5],&etudiant[md].name[6],&etudiant[md].name[7],&etudiant[md].name[8],&etudiant[md].name[9],&etudiant[md].name[10],&etudiant[md].name[11],&etudiant[md].name[12],&etudiant[md].name[13],&etudiant[md].name[14]); // saisie nom a rechercher

    }break;

    case 2:{ // modifier prenom

    printf(“\nDonnez le nouveau Prenom –S.V.P– –il faux ecrire 15 caracteres \npour les caracteres de plus vous pouvez les replacez par des points\n\01”);
    scanf(“%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c”,&etudmdant[md].prenom[0],&etudmdant[md].prenom[1],&etudmdant[md].prenom[2],&etudmdant[md].prenom[3],&etudmdant[md].prenom[4],&etudmdant[md].prenom[5],&etudmdant[md].prenom[6],&etudmdant[md].prenom[7],&etudmdant[md].prenom[8],&etudmdant[md].prenom[9],&etudmdant[md].prenom[10],&etudmdant[md].prenom[11],&etudmdant[md].prenom[12],&etudmdant[md].prenom[13],&etudmdant[md].prenom[14]);// samdsmde prenom

    }break;

    case 3:{ //modifier C.I.N

    printf(“\nDonnez nouveau numero C.I.N\n”);
    scanf(“%i”,&etudiant[md].cin);
    }break;

    case 4:{ //modifier sexe

    printf(“\nDonner nouveau sexe !!!!\n”);
    scanf(“%c”,&etudiant[md].sexe[1]);

    }break;

    case 5:{ //modifier niveau
    while(etudiant[md].niveau<=0)
    {
    printf(“\nDonnez nouvea niveau\n”);
    scanf(“%i”,&etudiant[md].niveau);
    }
    }break;

    case 6:{ //modifier age
    while(etdiant[md].age)
    {
    printf(“\nDonnez nouveau age\n”);
    scanf(“%i”,&etudiant[md].age);
    }

    }break;
    default: {printf(“Modification n’est pas reussite”);c=0;break;} //message de modification nulle
    }
    if(c!=0)printf(“\nModificatin reussite …..\n”); //modification positive
    printf(“\nDonnez votre choix –S.V.P–“);
    printf(“\n1-refaire une autre modification”);
    printf(“\n2-revenir au menu”);
    scanf(“%i”,&c);
    switch(c)
    {
    case 1:modif(md);break;
    case 2:main();break;
    }
    }
    /* fin procedure modification */

    /************************************************************************************************************/

    /************************************************************************************************************/
    /*********************************************** Bienvenue **************************************************/
    /******************** Procedure principal de programme gestion de scolarite *********************************/
    /************************************************************************************************************/
    /************************************************************************************************************/

    void main()

    {
    etudianttype etudiant[n];
    ttmatiere tttmatiere[n];
    int all=0,one=7;
    int trc=all;
    // debut bienvenue
    while (one!=0)
    {
    printf(“\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1”);

    printf(“——————————————————————————–“);

    printf(“———— Bienvenue sur le menu de gestion scolarite E.S.T.I —————-“);
    printf(“——————————————————————————–“);
    printf(“\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1”);

    // fin bienvenue
    printf(“\nEntrez votre choix\n”);
    printf(“\1-1-Saisie d’un nouveau etudiant\n”);
    printf(“\1-2-Recherche d’un etudiant\n”);
    printf(“\1-3-Modification de parametres d’un etudiant\n”);
    printf(“\1-4-Afficher la fiche d’un etudiant\n”);
    printf(“\1-5-Quitter\n”);
    scanf(“%i”,&one);

    switch(one)

    {
    case 1:{
    clrscr();
    vidage(all); // vidage de la partie a saisir pour avoir une saiie reussite et parfaite
    saisie(all);all++ // incrementation de nb total d’etudiant en supposant qu’il y a un nouveau elmen saisie

    }break;
    case 2:{
    clrscr();
    recherche(); // recherche par parametres

    }break;
    case 3:{
    clrscr();
    printf(“——————————————————————————–“);
    printf(“———-pour Modifier un element il faux le rechercher en premier lieu——–“)
    printf(“——————————————————————————–\n”);
    recherche();
    modif(trc);

    }break;
    case 4:{

    clrscr();
    printf(“——————————————————————————–“);
    printf(“———-pour AFFICHER un element il faux le rechercher en premier lieu——–“)
    printf(“——————————————————————————–\n”);
    recherche();
    affichage(trc);

    }break;
    case 5:{;}break;

    default:{printf(“votre choix n’est pas valide “);getch();main();}break;
    }
    }
    printf(“——————————————————————————–“);
    printf(“————————Merci d’avoir choisi notre programme——————–“);
    printf(“——————————————————————————–\n”);

    }

    my compiler is on ……
    errors are
    Code:

    ——————–Configuration: bjh – Win32 Debug——————–
    Compiling…
    jnk.cpp
    c:\bjh\jnk.cpp(89) : error C2447: missing function header (old-style formal list?)
    c:\bjh\jnk.cpp(112) : error C2447: missing function header (old-style formal list?)
    c:\bjh\jnk.cpp(559) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    jnk.obj – 3 error(s), 0 warning(s)
    Last edited by enjoy; 05-02-2004 at 02:22 PM. Reason: adding errors
    05-02-2004 #2
    XSquared XSquared is offline
    C++ Developer
    XSquared’s Avatar Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    1: #include “stdio.h”
    #include <stdio.h>

    2: void main()
    int main()

    What errors are you getting?
    Naturally I didn’t feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! – Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death – Stewie
    05-02-2004 #3
    enjoy enjoy is offline
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    i’m using visual c++
    “stdio.h” equivalent <stdio.h>
    int main() == void main() == void main(void)
    05-02-2004 #4
    XSquared XSquared is offline
    C++ Developer
    XSquared’s Avatar Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >”stdio.h” equivalent <stdio.h>
    Nope.

    >int main() == void main() == void main(void)
    int main() != void main() != void main(void)
    Search the fscking board.
    Naturally I didn’t feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! – Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death – Stewie
    05-02-2004 #5
    enjoy enjoy is offline
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    try to compile this program and see the errors
    please …..
    05-02-2004 #6
    enjoy enjoy is offline
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
    ?
    1
    try to compile my code because my compiler is busy … :d
    05-02-2004 #7
    anonytmouse anonytmouse is offline
    Yes, my avatar is stolen
    anonytmouse’s Avatar Join Date
    Dec 2002
    Posts
    2,544
    Here is the biggest problem:
    Code:
    float moyenne(int m);
    {
    float r,sc,sm;
    That semicolon should not be there.
    Also:
    Code:
    ?
    1
    2
    3
    int classement(int c);
    {
    int r=all;
    Once you have fixed those, you need to fix these:
    Code:
    ?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    testbed3.c(67) : error C2065: ‘i’ : undeclared identifier
    testbed3.c(67) : error C2065: ‘etudiant’ : undeclared identifier
    testbed3.c(67) : error C2109: subscript requires array or pointer type
    testbed3.c(69) : error C2065: ‘tttmatiere’ : undeclared identifier
    testbed3.c(69) : error C2109: subscript requires array or pointer type
    testbed3.c(69) : error C2109: subscript requires array or pointer type
    testbed3.c(70) : error C2109: subscript requires array or pointer type
    testbed3.c(88) : error C2065: ‘all’ : undeclared identifier

    testbed3.c(294) : fatal error C1003: error count exceeds 100; stopping compilation
    05-02-2004 #8
    enjoy enjoy is offline
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    Code:
    testbed3.c(67) : error C2065: ‘i’ : undeclared identifier
    [ b] i is declared in any function who is used ???[/b]
    testbed3.c(67) : error C2065: ‘etudiant’ : undeclared identifier
    etudiant is declared in the main function
    testbed3.c(67) : error C2109: subscript requires array or pointer type
    ?????
    testbed3.c(69) : error C2065: ‘tttmatiere’ : undeclared identifier
    tttmatiere is declared in the main
    testbed3.c(69) : error C2109: subscript requires array or pointer type
    testbed3.c(69) : error C2109: subscript requires array or pointer type
    testbed3.c(70) : error C2109: subscript requires array or pointer type
    ????????????!!!!!!
    testbed3.c(88) : error C2065: ‘all’ : undeclared identifier
    all is deeclared in the main

    Code:
    ?
    1
    explain me please these errors
    05-02-2004 #9
    anonytmouse anonytmouse is offline
    Yes, my avatar is stolen
    anonytmouse’s Avatar Join Date
    Dec 2002
    Posts
    2,544
    ‘Undeclared Identifier’ simply means that you have not declared that variable in that scope.

    >> etudiant is declared in the main function <<

    That means it is available in the main() function. It is not available in other functions unless you pass it to them or declare it at file scope.
    05-02-2004 #10
    enjoy enjoy is offline
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    what’s the file scope
    excuse me my english is not good i’m just a beginner in english
    05-02-2004 #11
    anonytmouse anonytmouse is offline
    Yes, my avatar is stolen
    anonytmouse’s Avatar Join Date
    Dec 2002
    Posts
    2,544
    Code:
    /* Declared outside a function. Has global scope. Visible in all
    * functions in the project. */
    int a;

    /* Declared outside a function with static specifier. Has file scope.
    * Visible in all functions in this file only. */
    static int b;

    int main(void)
    {

Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.