當前位置: 首頁>>代碼示例>>Java>>正文


Java Console.printf方法代碼示例

本文整理匯總了Java中java.io.Console.printf方法的典型用法代碼示例。如果您正苦於以下問題:Java Console.printf方法的具體用法?Java Console.printf怎麽用?Java Console.printf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.Console的用法示例。


在下文中一共展示了Console.printf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: userCredentials

import java.io.Console; //導入方法依賴的package包/類
/**
 * ask user for Credentials
 */
private void userCredentials() {
    AdvancedEncryptionStandard myEncryption = new AdvancedEncryptionStandard();
    Scanner input = new Scanner(System.in, "utf-8");
    Console console = System.console();
    console.printf("Username: ");
    this.username = input.nextLine();

    //Password Field is not prompted
    console.printf("Password: ");
    char[] pass = console.readPassword();
    this.decryptPassword = new String(pass);
    //ecrypts input user password
    this.encryptPassword = myEncryption.encrypt(decryptPassword);
    this.password = encryptPassword;
    System.out.println();
}
 
開發者ID:GrigorisParaskevakos,項目名稱:BankAccount_PasaskevakosG_BootCamp3,代碼行數:20,代碼來源:LoginScreen.java

示例2: main

import java.io.Console; //導入方法依賴的package包/類
public static void main( String[] args ) {
        double d = -19.080808;
        System.out.println( "-> " + String.valueOf( d ) );

// string tem 2 caracteres Scandinavos
        String scandString = "å, ä, and ö";
// tentando exibir caracteres scandinavos diretamente com println
        System.out.println(
                "Printing scands directly with println: " + scandString );
// agora com um objeto console
        Console console = System.console();
        if ( console != null ) {
            console.printf(
                    "Printing scands thro' console's printf method: " + scandString );
        }
    }
 
開發者ID:juliocnsouzadev,項目名稱:ocpjp,代碼行數:17,代碼來源:SpecialCharHandling.java

示例3: doConsole

import java.io.Console; //導入方法依賴的package包/類
private void doConsole() throws Exception
{
    Console console = System.console();

    if (console != null) // IDE not support
    {
        String className = console.readLine("> ");

        CommandManager commandManager = new CommandManager();

        while (commandManager.execute(new CommandFactory().createCommand(className)))
        {
            console.printf(NEW_LINE);

            className = console.readLine("> ");
        }
    }
}
 
開發者ID:geekflow,項目名稱:light,代碼行數:19,代碼來源:Main.java

示例4: main

import java.io.Console; //導入方法依賴的package包/類
public static void main( String[] args ) {
    String str = " ";
    String[] splited = str.split( " " );
    System.out.println( "-> " + splited.length );

    Console console = System.console();
    /*
     * Se a JVM é invocada indiretamente pela IDE, ou se a JVM é invocada a
     * partir de um processo de background, então o chamada de método
     * System.console () irá falhar e retornar nulo.
     */
    if ( console == null ) {
        System.out.println(
                "Executando app de uma ide... objeto console nao recuperado" );
    }
    else {
        console.printf( console.readLine() );
    }
}
 
開發者ID:juliocnsouzadev,項目名稱:ocpjp,代碼行數:20,代碼來源:Echo.java

示例5: configureConversion

import java.io.Console; //導入方法依賴的package包/類
private static DocumentType[] configureConversion(Console console, Map<DocumentType, Set<DocumentType>> supportedConversions) {
    console.printf("The connected converter supports the following conversion formats:%n");
    Map<Integer, DocumentType[]> conversionsByIndex = new HashMap<Integer, DocumentType[]>();
    int index = 0;
    for (Map.Entry<DocumentType, Set<DocumentType>> entry : supportedConversions.entrySet()) {
        for (DocumentType targetType : entry.getValue()) {
            conversionsByIndex.put(index, new DocumentType[]{entry.getKey(), targetType});
            console.printf("  | [%d]: '%s' -> '%s'%n", index++, entry.getKey(), targetType);
        }
    }
    do {
        console.printf("Enter the number of the conversion you want to perform: ");
        try {
            int choice = Integer.parseInt(console.readLine());
            DocumentType[] conversion = conversionsByIndex.get(choice);
            if (conversion != null) {
                console.printf("Converting '%s' to '%s'. You can change this setup by entering '\\f'.%n", conversion[0], conversion[1]);
                return conversion;
            }
            console.printf("The number you provided is not among the legal choices%n");
        } catch (RuntimeException e) {
            console.printf("You did not provide a number%n");
        }
    } while (true);
}
 
開發者ID:documents4j,項目名稱:documents4j,代碼行數:26,代碼來源:StandaloneClient.java

示例6: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
	Console console = System.console();
	if (console != null) {
		String user = new String(console.readLine("Enter User:", new Object[0]));
		String pwd = new String(console.readPassword("Enter Password:", new Object[0]));
		console.printf("User name is:%s", new Object[] { user });
		console.printf("Password is:%s", new Object[] { pwd });
	} else {
		System.out.println("No Console!");
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:12,代碼來源:ConsoleDemo.java

示例7: handle

import java.io.Console; //導入方法依賴的package包/類
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    Console console = System.console();
    console.printf("Please enter your Rider Auto Parts password: ");
    char[] passwordChars = console.readPassword();
    String passwordString = new String(passwordChars);
    pc.setPassword(passwordString);        
}
 
開發者ID:camelinaction,項目名稱:camelinaction2,代碼行數:9,代碼來源:StdInPasswordCallback.java

示例8: main

import java.io.Console; //導入方法依賴的package包/類
/**
 * Main driver, runs the WGen application.
 * 
 * @param args Program arguments, not used
 * @throws Throwable On I/O error
 */
public static void main(String[] args) throws Throwable
{
	Console c = System.console();
	if (c == null)
		FSystem.errAndExit("You are not running in CLI mode.");

	c.printf("Welcome to WGen!%nThis utility encodes and stores usernames/passwords%n%n");

	HashMap<String, String> ul = new HashMap<>();
	while (true)
	{
		String u = c.readLine("Enter a username: ").trim();
		c.printf("*** Characters hidden for security ***%n");
		char[] p1 = c.readPassword("Enter password for %s: ", u);
		char[] p2 = c.readPassword("Re-enter password for %s: ", u);

		if (Arrays.equals(p1, p2))
			ul.put(u, new String(p1));
		else
			c.printf("ERROR: Entered passwords do not match!%n");

		if (!c.readLine("Continue? (y/N): ").trim().matches("(?i)(y|yes)"))
			break;

		c.printf("%n");
	}

	if (ul.isEmpty())
		FSystem.errAndExit("You did not make any entries.  Doing nothing.");

	StringBuilder sb = new StringBuilder();
	ul.forEach((k, v) -> sb.append(String.format("%s\t%s%n", k, v)));

	byte[] bytes = Base64.getEncoder().encode(sb.toString().getBytes());
	Files.write(px, bytes);
	Files.write(homePX, bytes);

	c.printf("Successfully written out to '%s' and '%s'%n", px, homePX);
}
 
開發者ID:fastily,項目名稱:jwiki,代碼行數:46,代碼來源:WGen.java

示例9: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
Console console = System.console();
MyHeap heap;
{
    String minOrMax = console.readLine("Min heap or max heap? (m/M) ");
    heap = new MyHeap(minOrMax.equals("M"));
}
for (String cmd = console.readLine("Type a number to add, 'r' to remove, or 'x' to exit: ");
     !cmd.equals("x");
     cmd = console.readLine("> ")) {
    if (cmd.equals("r")) {
	if (heap.size() > 0) {
	    console.printf("Removed %d\n", heap.remove());
	    console.printf(heap.toString() + '\n');
	}
	else {
	    console.printf("Cannot remove from empty heap\n");
	}
    }
    else {
	try {
	    int addMe = Integer.parseInt(cmd);
	    heap.add(addMe);
	    console.printf("Added %d\n", addMe);
	    console.printf(heap.toString() + '\n');
	}
	catch (NumberFormatException e) {
	    console.printf("Invalid command: %s\n", cmd);
	}
    }
}
   }
 
開發者ID:aidan-fitz,項目名稱:BeyondTheCollegeBoard,代碼行數:33,代碼來源:Driver.java

示例10: getPasswordFromConsole

import java.io.Console; //導入方法依賴的package包/類
private static String getPasswordFromConsole(String botName) {
    logger.info("Requesting password from console");
    String password = null;
    try {
        Console console = System.console();
        if (console == null) throw new RuntimeException("System.console() is null");
        console.printf("Please enter the password of '%s'\n", botName);
        char[] passwordChars = console.readPassword("Password: ");
        password = new String(passwordChars);
    } catch (Exception e) {
        logger.error("Failed to get password from console", e);
        System.exit(1);
    }
    return password;
}
 
開發者ID:jessewebb,項目名稱:gweebot,代碼行數:16,代碼來源:GweeBot.java

示例11: cmdLock

import java.io.Console; //導入方法依賴的package包/類
private void cmdLock() {
	readAndLockRepository();
	Console console = System.console();
	if (console != null) {
		console.printf("Repository locked. Press enter to unlock.\n");
		console.readLine();
		console.printf("Repository unlocked.\n");
	}
}
 
開發者ID:ruediste,項目名稱:btrbck,代碼行數:10,代碼來源:CliMain.java

示例12: prompt

import java.io.Console; //導入方法依賴的package包/類
/**
 * Prompt.
 *
 * @return the credentials
 */
public static Credentials prompt() {
  Console console = System.console();
  if (console == null) {
    System.err.println("Couldn't get Console instance");
    System.exit(-1);
  }
  console.printf("username:");
  String username = console.readLine().trim();
  char[] passwordArray = console.readPassword("password for %s:", username);
  String password = new String(passwordArray);
  return new Credentials(username, password);
}
 
開發者ID:apache,項目名稱:lens,代碼行數:18,代碼來源:Credentials.java

示例13: insertCommand

import java.io.Console; //導入方法依賴的package包/類
private void insertCommand(Console c) {
    String command = sanitizeParameter(c.readLine(command_prompt));
    logger.debug("Received the following command " + command);

    String params = sanitizeParameter(c.readLine(parameters_prompt));
    logger.debug("Received the following parameters " + params);

    // invoke insert command
    LogEntry entry = invokeInsertCommandOp(command, params);
    c.printf("Invoked insert command and received %s\n", entry.toShortString());
}
 
開發者ID:filipecampos,項目名稱:raft4ws,代碼行數:12,代碼來源:Client.java

示例14: readData

import java.io.Console; //導入方法依賴的package包/類
private void readData(Console c) {
    String option = sanitizeParameter(c.readLine(read_prompt));
    logger.debug("Received the following option " + option);

    int op = Integer.parseInt(option);
    String uid = null;
    switch (op) {
        
        case 1:
            // get specific entry
            uid = sanitizeParameter(c.readLine(entry_prompt));
            c.printf("Retrieving the entry with UID %s\n", uid);
        case 2:
            // get last entry
            LogEntry entry = invokeReadOp(uid);
            if(entry != null)
            {
                if(entry.getSuccess())
                    c.printf("Retrieved %s\n", entry);
                else
                    c.printf("Received %s\n", entry.getResponse());
            }
            else
            {
                c.printf("Entry is null!\n");
            }
            break;
    }
}
 
開發者ID:filipecampos,項目名稱:raft4ws,代碼行數:30,代碼來源:Client.java

示例15: sayHello

import java.io.Console; //導入方法依賴的package包/類
private static void sayHello(IConverter converter, Logger logger, Console console) {
    console.printf("Welcome to the documents4j client!%n");
    boolean operational = converter.isOperational();
    if (operational) {
        logger.info("Converter {} is operational", converter);
    } else {
        logger.warn("Converter {} is not operational", converter);
    }
}
 
開發者ID:documents4j,項目名稱:documents4j,代碼行數:10,代碼來源:StandaloneClient.java


注:本文中的java.io.Console.printf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。