Created
March 10, 2011 05:45
-
-
Save alextucker/863630 to your computer and use it in GitHub Desktop.
Java Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.Scanner; | |
public class Example { | |
private int numQuestions; | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Example e = new Example(); | |
e.speak(); | |
while (e.setQuestions()) {} | |
e.speak(); | |
} | |
public Example() { | |
this.numQuestions = 0; | |
} | |
public void speak() { | |
System.out.println("Current number of questions: " + numQuestions); | |
} | |
public boolean setQuestions() { | |
int questions; | |
System.out.println("Enter how many questions you want: "); | |
try { | |
Scanner s = new Scanner(System.in); | |
questions = s.nextInt(); | |
this.numQuestions = questions; | |
return false; | |
} catch (Exception e) { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment