Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

convert Java code to pseudo code

843785Jul 24 2008 — edited Jul 24 2008
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");
try{
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;
}

}

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 21 2008
Added on Jul 24 2008
25 comments
9,717 views