1. Member
Join Date
Oct 2008
Posts
39
Rep Power
0

if and then while?

Is there a way i can say while Variable is over 0 compute within a if statement, please see below:

public class BicylceGears{

public static void main (String[]args){

int fSprocket;
int rSprocket;
double ratio;

if( (wheelRad <= 0) || (fSprocket <= 0) || (rSprocket <= 0)){

System.out.println("message Error, invalid value and do not let your program continue.");

}else{

System.out.println("ratio to previous "+ratio);

}

System.out.println("ratio to previous "+ratio);

}
}//end main

}//end class

2. Java Code:
```public class BG{
public static void main (String[] args){
int fSprocket;
int rSprocket;
double ratio;

if( (wheelRad <= 0) || (fSprocket <= 0) || (rSprocket <= 0)){

System.out.println("message Error, invalid value " +
"and do not let your program continue.");
// Program execution will move to the [i]while[/i] loop from here.

}else{

System.out.println("ratio to previous "+ratio);

}

// This loop will run until the value of eRad falls below zero.
// What, inside the curley braces, will cause it to do this?
// Maybe a different test would work better. What changes here?

// Changes to this variable affect/influence the
// test condition for the while loop. How will the
// value of this variable change inside this loop?

System.out.println("ratio to previous "+ratio);

// What is this statement doing?
}
}
}

class UserInput {
static java.util.Scanner scanner = new java.util.Scanner(System.in);

return Double.parseDouble(scanner.nextLine());
}

return Integer.parseInt(scanner.nextLine());
}
}```

3. Do you mean
Java Code:
```if (foo) {
while (bar) {
// do something
}
}```
Here's a suggestion. In a simple word processor, write out, in plain language, what you want your program to do. Avoid using any programming language, within reason. Put one step on each line. Use indentation to help you see structure.

When you can read through the steps and they all make sense, then turn what you have into Java.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•