Explore BrainMass
Share

# Converting Java to pseudo-code

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Public class testOperators
{
public static void main(String[] args)
{
int x;
int y = 12
double z = 13.0;
x = 14
System.out.println("x + y + z = " + (x + y +z));
x += y;
y--;
z++;
z *= x;
System.out.println("x + y + z = " + (x + y + z));
}
}

https://brainmass.com/computer-science/pseudocode/converting-java-to-pseudo-code-200403

#### Solution Preview

The trickiest part of this java code is dealing with the arithmetic operators. In particular there are ...

#### Solution Summary

This solution starts with a few expressions written in Java and converts that to a pseudo-code algorithm.

\$2.19

## A Brief Explanation of Pseudo-Code

public class WordSearch {

private static ArrayList<String> board = new ArrayList<String>();
private static Scanner scanner;

String line;
while (true) {
line = scanner.nextLine();
if (line.equals(""))

break;
}
}

public static void printBoard() {
int rows = getRows();
for (int row=0; row<rows; row++)
System.out.println(board.get(row));
}

public static int getRows() {
return board.size();
}

public static int getCols() {
return board.get(0).length();
}

public static void createScanner() {
try {
scanner = new Scanner(new java.io.File("WordSearchInput.txt"));
} catch (Exception e) {
System.out.println();
System.exit(1);
}
}

public static void processWords() {
while (scanner.hasNext()) {
String word = scanner.next();
findWord(word);
}
}

public static void findWord(String word) {
int rows = getRows();
int cols = getCols();
for (int row=0; row<rows; row++)
for (int col=0; col<cols; col++)
findWord(word,row,col);
}

public static void findWord(String word, int row, int col) {
for (int drow=-1; drow<=1; drow++)
for (int dcol=-1; dcol<=1; dcol++)
findWord(word,row,col,drow,dcol);
}

public static void findWord(String word, int row, int col, int drow, int dcol) {
int rows = getRows();
int cols = getCols();
for (int offset=0; offset<word.length(); offset++) {
int targetRow = row + offset*drow;
int targetCol = col + offset*dcol;
if ((targetRow < 0) ||
(targetRow >= rows) ||
(targetCol < 0) ||
(targetCol >= cols))

return;
char boardChar = board.get(targetRow).charAt(targetCol);
char wordChar = word.charAt(offset);
if (boardChar != wordChar)
// mismatch, so we're done
return;
}
System.out.printf("%s at %d,%d direction %d,%dn",
word, row, col, drow, dcol);
}

public static void main(String[] args) {
createScanner();