Skip to content

Instantly share code, notes, and snippets.

@alextucker
Created March 10, 2011 05:45
Show Gist options
  • Save alextucker/863630 to your computer and use it in GitHub Desktop.
Save alextucker/863630 to your computer and use it in GitHub Desktop.
Java Example
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