Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my.pack;
- import java.util.Scanner;
- import java.util.function.Function;
- public class David1 {
- public static void main(String[] args) {
- String inputString = "hello";
- doWhile(new Function<String, Boolean>() {
- @Override
- public Boolean apply(String t) {
- if (t == null)
- return false;
- return t.equals(inputString);
- }
- }, "input string should be " + inputString + ".");
- }
- public static void doWhile(Function<String, Boolean> conditionChecker, String errMsg) {
- Scanner s = new Scanner(System.in);
- String next = null;
- do {
- if (next != null)
- System.err.println(errMsg);
- next = s.nextLine();
- }
- while(!conditionChecker.apply(next));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement