Java Coding Converted to Pseudo Code

How to transform that pseudocode into java code?

  1. stackedPixels could be an array or any sort of Collection that can store the pixel objects.
  2. stackedPixels ∪ pixel represents appending the current pixel to stackedPixels

Is my understanding of writing a pseudo code(java) correct?

Pseudocode is a more informal expression.
It is language independent.
You do not have to declare variables in pseudocode.
You just have to get the message across in a good manner.

For printf you can use print "message"

Hi, you can check out the following links they will definitely help.

link 1

link 2

link 3

Java pseudocode to code

Just take one step at a time, and when that step completely works, proceed to the next step.

An example:

Here's your pseudo-code (which, by the way, is a great way to start):

class Visit
Print out "Have you bought anything?" (Pop up to answer)
if the answer is “no”
print “Have a nice day!”
exit program
if else the answer is “yes”
continue
if else the answer is not “no” nor “yes”
ask again

Let's just implement and test the "is the answer yes-or-no" functionality:

/**
<P>{@code java MyHomeworkMainClass}</P>
**/
public class MyHomeworkMainClass {
public static final void main(String[] ignored) {
System.out.println("Visit.isUserInputYesNo(null)=" + Visit.isUserInputYesNo(null));
System.out.println("Visit.isUserInputYesNo(\"gibberish\")=" + Visit.isUserInputYesNo("gibberish"));
System.out.println("Visit.isUserInputYesNo(\"yes\")=" + Visit.isUserInputYesNo("yes"));
System.out.println("Visit.isUserInputYesNo(\"no\")=" + Visit.isUserInputYesNo("no"));
}
}
class Visit {
public static final boolean isUserInputYesNo(String input) {
return (input != null &&
(input.equals("yes") || input.equals("no")));
}
}

Now run it and see if it does what you want:

[C:\java_code\]java MyHomeworkMainClass
Visit.isUserInputYesNo(null)=false
Visit.isUserInputYesNo("gibberish")=false
Visit.isUserInputYesNo("yes")=true
Visit.isUserInputYesNo("no")=true

It does. Now add something else small to this and just keep going until you're done. For particularly difficult parts, it may be beneficial to create a completely separate class, with its own testing class. Then at the end, merge it all together. And never get rid of your testing functions, which will always be there for diagnosing future problems.

Good luck!

Java: How to covert pseudo code for a stack into an array

You have basically to perform operations on the array using the FIFO propriety.

public ArrayStack( )
{
theArray = new String[InitialSize];
topOfStack = -1;
}

Every time you add an element to your array (push) you do topOfStack++; and insert the element on the "topOfStack" position of the array. By doing topOfStack++ you are keeping track of the array position that became the new top of the stack.

When you do pop you must check if the array is not empty, return the element on array[topOfStack] and do topOfStack--;. Because the top is now the previous position on the array.

If you need more space for your array because the stack is full (topOfStack == InitialSize) you have to create another array with more space, for example :

private void doubleArray( )
{
String [] newArray = new String[ theArray.length * 2 ];
for( int i = 0; i < theArray.length; i++ )
newArray[ i ] = theArray[ i ];
theArray = newArray;
}

For stating, this is roughly what you need to look for, naturally, there are many more details to look into. Nevertheless, try it out yourself, and when you have doubts look for resources such as this.

Pseudo Code to Java translation error

When you do,

double x = 7.0;
double y = Math.pow(x, 1000.0); // <-- INFINITY

you do exceed the precision of double and you get Double.POSITIVE_INFINITY

System.out.println(y);

Output is

Infinity

When you cast that to int you get Integer.MAX_VALUE which is 2^31-1 or 2147483647. If you want to get a more convincing result you could use BigInteger like

int n = BigInteger.valueOf(7).pow(1000).intValue();
System.out.println(n);

Output is

432069569

Of course, the real result is obtained by

System.out.println(BigInteger.valueOf(7).pow(1000));

Which results in a very big number indeed.

Pseudocode in java?

Pseudocode, i think, doesn't have a predefined syntax. just follow two rules:

  • It should be plain english with common programming constructs.

  • It should be generic, not specific to any language.

Following should fit:

Step 1: Initialize an empty string. (say str)

Step 2: Construct a new 'Finch' object.

Step 3: BEGIN LOOP

Fetch 'FinchMenu' from 'Finch' object.

assign 'FinchMenu' to 'str'

IF 'FinchMenu' is "Back and forward"

Call 'RunAccelerationTest' method with 'str' as argument.

END IF

END LOOP


Related Topics



Leave a reply



Submit