Console printf - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Console printf method.

This code example shows how to use the following methods:printf
        return theConsole.format(fmt,args);
    } 
 
    @Override 
    public void printf(String format, Object... args) throws IllegalFormatException {
        theConsole.printf(format,args);
    } 
 
    @Override 
    public String readLine(String fmt, Object... args) throws IOError {
        return theConsole.readLine(fmt,args);
    } 
 
    @Override 
    public char[] readPassword(String fmt, Object... args) throws IllegalFormatException, IOError {
        return theConsole.readPassword(fmt,args);
    } 
 
    @Override 
    public Console getConsole() {
7
CodeRank
This code example shows how to use the following methods:printf
 
   @Override 
   public void execute(Console console, String argLine) {
      String[] args = argLine.split("\\s");
      if (args.length != getNumArgs() + 1) {
         console.printf("The argument list is incorrect\n");
         return; 
      } 
 
      String nameOfShares = args[1];
      try { 
         SharesUpdate sharesUpdate = (SharesUpdate) getSharesUpdateViaRest(composeKey(nameOfShares, "last"));
         if (sharesUpdate != null) {
            console.printf("------------- %s -------------\n", nameOfShares);
            console.printf("Date:  %s\n", sharesUpdate.getDate().toString());
            console.printf("Value: %f USD\n", sharesUpdate.getValue());
         } else { 
            console.printf("Last stock value for " + nameOfShares + " not found.\n");
         } 
      } catch (Exception e) {

5
CodeRank
This code example shows how to use the following methods:printf
package cz.tomascejka.app.console.command; 
 
import java.io.Console; 
 
public class CommandHelp implements Command { 
 
	public static final String KEY="help";
 
	public Object execute(final Console console) {
		console.printf("WNConsole commands:\n");
		final StringBuilder list = new StringBuilder();
		list.append("   help : ").append("Show this help").append("\n");
		list.append("  login : ").append("Allow to login in WNConsole").append("\n");
		list.append("   list : ").append("Show list all registered users from storage").append("\n");
		list.append("    add : ").append("Add user to storage").append("\n");
		list.append(" delete : ").append("Remove user from storage [only logged]").append("\n");
		list.append(" logout : ").append("Allow to logout").append("\n");
		list.append("   exit : ").append("Exit from console WNConsole").append("\n");
		console.printf(list.toString());
		return true; 

5
CodeRank
This code example shows how to use the following methods:printf, readLine
package cz.tomascejka.app.console.command; 
 
import java.io.Console; 
 
public class CommandExit implements Command { 
 
	public static final String KEY="exit";
 
	public Object execute(final Console console) {
		final String answer = console.readLine("Are you sure? [y/n]: ");
		boolean retval = false;
		if("y".equals(answer)){
			retval = true;
		} else if("n".equals(answer)) {
			retval = false;
		} else { 
			console.printf("Uknown answer: "+answer);
			retval = false;
		} 
		return retval;

5
CodeRank
This code example shows how to use the following methods:flush, printf
        return readLine(); 
    } 
 
    @Override 
    public void printf(String format, Object... args) {
        console.printf(format, args);
        console.flush();
    } 
 
    @Override 
    public String readLine() {
        return console.readLine();
    } 
 
    @Override 
    public void putstr(String s) {
        console.writer().print(s);
        console.flush();
    } 
 
4
CodeRank
This code example shows how to use the following methods:printf
        assertEquals("1 hello", prompt);
    } 
 
    public void test_printf_LString_LObject() { 
        Calendar c = new GregorianCalendar(1983, 2, 21);
        assertSame(console, console.printf("%1$tm %1$te,%1$tY", c));
        String prompt = new String(((ByteArrayOutputStream)out).toByteArray());
        assertEquals("03 21,1983", prompt);
    } 
 
    public void test_reader() throws IOException { 
        Reader reader1 = console.reader();
        assertTrue(reader1.ready());
        Reader reader2 = console.reader();
        assertSame(reader1, reader2);
    } 
 
    public void test_readLine() { 
        String line = console.readLine();
        assertEquals("hello world", line);
4
CodeRank
This code example shows how to use the following methods:printf
    } 
 
    @Override 
    public void header(String fmt, Object... args) {
      fmt = fmt.replaceAll("\n", "\n*** ");
      console.printf("\n*** " + fmt + "\n*** \n\n", args);
    } 
  } 
 
  private static class Batch extends ConsoleUI { 
    @Override 
    public boolean isBatch() { 
      return true; 
    } 
 
    @Override 
    public boolean yesno(Boolean def, String fmt, Object... args) {
      return def != null ? def : true;
    } 
 
4
CodeRank
This code example shows how to use the following methods:printf
 
	public static void printf(String formatString, Object... args) {
		 
		try { 
			if (console != null) {
				console.printf(formatString, args);
			} else { 
				System.out.print(String.format(formatString, args));
			} 
		} catch (IllegalFormatException e) {
			System.err.print("Error printing...\n");
		} 
	} 
	 
	public static void print(String s) {
		printf("%s", s);
	} 
	 
	public static String readLine(String userPrompt) throws IOException {
		String line = "";
4
CodeRank
This code example shows how to use the following methods:printf
    } 
 
    @Override 
    public void header(String fmt, Object... args) {
      fmt = fmt.replaceAll("\n", "\n*** ");
      console.printf("\n*** " + fmt + "\n*** \n\n", args);
    } 
 
    @Override 
    public void message(String fmt, Object... args) {
      console.printf(fmt, args);
    } 
  } 
 
  private static class Batch extends ConsoleUI { 
    @Override 
    public boolean isBatch() { 
      return true; 
    } 
 
3
CodeRank
This code example shows how to use the following methods:printf
  } 
 
  @Override 
  public void problemOccured(final String s) {
    if (console != null)
      console.printf("|E| %s", s);
    else 
      System.out.printf("|E| %s", s);
  } 
 
  @Override 
  public void depthChanged(final int depth) {
    if (console != null)
      console.printf("|i| depth %d\n", depth);
    else 
      System.out.printf("|i| depth %d\n", depth);
  } 
 
  @Override 
  public void onePhaseStatistics(final long checks, final long hits) {
3
CodeRank
printf Method Overview
A convenience method to write a formatted string to this console's output stream using the specified format string and arguments.
See Code Examples for other Java 8 Console Methods: