当前位置: 首页>>代码示例>>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;未经允许,请勿转载。