This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes help convert java code to pseudo code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help convert java code to pseudo code" Watch "help convert java code to pseudo code" New topic

help convert java code to pseudo code

jacelyn chia

Joined: Jul 24, 2008
Posts: 1
any kind soul can help me convert Java code to pseudo code??? My due is 20hrs later !!! please help

package assignment;

import javax.swing.JOptionPane;
import javax.*;
public class Array
public static void main (String args[])
int inputInt = 0;
String errorMsg;
String wanaPlayInput;

do{ //set the flag for input as true at first
boolean inputAgain = true;

while (inputAgain){
String tryInput = JOptionPane.showInputDialog("How many numbers do you want to enter");
errorMsg = "";
inputInt = Integer.parseInt(tryInput);//try to change string into integer type
catch(Exception e){
errorMsg = e.getMessage();//input is not a number
//System.out.println("Exception!!" + errorMsg);
if(errorMsg.equals(""))//if no error msg, input is a number
inputAgain = false;//need not re-input

Double arrayInt [] = new Double [inputInt];

String numInputStr;
double numInput;
int pos;

for(int i=0; i<inputInt; i++){
pos = i + 1;
numInputStr = JOptionPane.showInputDialog("Enter number " + pos + " between 1 and 100");
numInput = Double.parseDouble(numInputStr);
while (numInput < 1 || numInput > 100){
//System.out.println("Number is less than 1 or more than 100");
numInputStr = JOptionPane.showInputDialog("Enter number " + pos + " between 1 and 100");
numInput = Double.parseDouble(numInputStr);
if(numInput > 0 && numInput < 101)
arrayInt[i] = numInput;

for(int j=0; j<inputInt; j++){
double number = arrayInt[j];

double squaredNum = calSquare(number);
//double squaredNum = Math.pow(number,2);
//System.out.println(number + " squared is : " + squaredNum);

double cubedNum = calCube(number);
//double cubedNum = Math.pow(number,3);
//System.out.println(number + " cubed is : " + cubedNum);

String msgBox = number + " squared is " + squaredNum + "\n" +
number + " cubed is " + cubedNum;

JOptionPane.showMessageDialog (null, msgBox);
//System.out.println("I am outside the loop");
wanaPlayInput = JOptionPane.showInputDialog("Do you want to continue (y/n)?");
while (wanaPlayInput.equalsIgnoreCase("y"));

public static double calSquare(double number){
double squaredNum = Math.pow(number,2);
//System.out.println("Using calSquare : " + number + " squared is : " + squaredNum);
return squaredNum;

public static double calCube(double number){
double cubedNum = Math.pow(number,3);
//System.out.println("Using calCube : " + number + " cubed is : " + cubedNum);
return cubedNum;

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11720

we don't do homework here for you. you should read this specifically, as well as most of the other topics here.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 42222
Welcome to JavaRanch.

Please find the code button below the "message" window when quoting code; it makes it easier to read.

It is usually easy to convert pseudo-code to code, so you should have no difficulty converting this sort of thing to Java:Now, with the similarity between pseudo-code and real code, it shouldn't be difficult to convert it back. Remember you don't have pseudo-code for a class, but for an algorithm, so it would be one block per method. I googled and found this and this, which looks better.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2782

Although I not helping to do your homework, pseudo code represents an algorithm and the code you posted isn't really a complex one to find out.

|Asking Good Questions|
Frances Hollis

Joined: Sep 02, 2006
Posts: 17
Crossposted in the Sun Forums. Twice.
I agree. Here's the link:
subject: help convert java code to pseudo code