当前位置: 首页>>代码示例>>Java>>正文


Java Scanner.nextBoolean方法代码示例

本文整理汇总了Java中java.util.Scanner.nextBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.nextBoolean方法的具体用法?Java Scanner.nextBoolean怎么用?Java Scanner.nextBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Scanner的用法示例。


在下文中一共展示了Scanner.nextBoolean方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connect

import java.util.Scanner; //导入方法依赖的package包/类
protected DTunnel connect(Socket socket) throws IOException {
    
    // Receive streams
    InputStream in = socket.getInputStream();
    OutputStream out = socket.getOutputStream();

    Scanner input = new Scanner(in);

    // Do handshake
    // Send protocol version
    out.write(DTP_VERSION);
    // Receive if the protocol version is supported
    if (!input.nextBoolean()) {
        throw new DTPWrongProtocolVersionException("Wrong version.");
    }
    
    // Send request
    PrintWriter out_writer = new PrintWriter(out);
    out_writer.print(destinationProtocol);
    // Wait for response
    int response = 0;
    int rcount = 0;
    for (; rcount < 4; rcount++) {
        response += input.nextBoolean() ? 1 : -1;
    }
    if (response < (rcount / 2))
        throw new ProtocolException("Couldn't find destination protocol host.");

    // Return tunnel
    return new DTunnel(destinationProtocol, in, out);
}
 
开发者ID:atpc,项目名称:dtp,代码行数:32,代码来源:DTPConnector.java

示例2: readBoolean

import java.util.Scanner; //导入方法依赖的package包/类
public static boolean readBoolean() throws Exception {
    //напишите тут ваш код
    Scanner sc = new Scanner(System.in);
    return sc.nextBoolean();

}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:7,代码来源:ConsoleReader.java

示例3: runModFile

import java.util.Scanner; //导入方法依赖的package包/类
private void runModFile(){

        /*
        *
        * Proper mod file example:
        *
        * true (mod car) true (mod gun) [path to car image] [path to gun image] [name of gun] [gun damage]
        *
        * even if false; enter corresponding type:
        *
        * false (mod car) true (mod gun) String [path to gun image] [name of gun] [gun damage]
        *
        * */

        // Path should be relative
        File modFile = new File("C:\\Users\\Hunter\\IdeaProjects\\The Trail JavaFX\\src\\com\\TheRedSpy15\\trail\\ModFile.txt");

        try {
            Scanner sc = new Scanner(modFile);

            Boolean modCar = sc.nextBoolean();
            Boolean modGun = sc.nextBoolean();

            String pathVehicle = sc.next();
            String pathGun = sc.next();
            String pathGID = sc.next();
            int pathDMG = sc.nextInt();

            if (modCar){

                setDefaultCarURL(pathVehicle);
                setCarSpriteURL(pathVehicle);
            }

            if (modGun){

                setGunSpriteURL(pathGun);
                setDefaultGunSpriteURL(pathGun);
                setBaseAttackDamage(pathDMG);
                setDefaultAttackDMG((byte) pathDMG);
                setGunID(pathGID);
                setDefaultGunID(pathGID);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:TheRedSpy15,项目名称:The-Trail,代码行数:48,代码来源:StartController.java

示例4: inputAllBaseTypes

import java.util.Scanner; //导入方法依赖的package包/类
public void inputAllBaseTypes() {    // input all basic data types and output the values
    Scanner input = new Scanner(System.in);
    
    // input the byte
    System.out.print("Enter an byte integer (from -128 to 127): ");
    byte byt = input.nextByte();
    
    // input the short
    System.out.print("Enter an short integer (from -32768 to 32767): ");
    short sho = input.nextShort();

    // input the int
    System.out.print("Enter an integer: ");
    int i = input.nextInt();

    // input the long 
    System.out.print("Enter an long integer: "); 
    long lon = input.nextLong();

    // input the float
    System.out.print("Enter a floating number: ");
    float flo = input.nextFloat();

    // input the double
    System.out.print("Enter a double floating number: ");
    double dou = input.nextDouble();

    // input the char
    System.out.print("Enter a character: ");
    String sTemp = input.next();
    char c = sTemp.charAt(0);

    // input the boolean
    System.out.print("Enter a boolean value: ");
    boolean bool = input.nextBoolean();

    // the outputs: 
    System.out.println("\nThe byte integer is: " + byt);
    System.out.println("The short integer is: " + sho);
    System.out.println("The integer is: " + i);
    System.out.println("The long integer is: " + lon);
    System.out.println("The floating number is: " + flo);
    System.out.println("The double floating number is: " + dou);
    System.out.println("The character is: " + c);
    System.out.println("The boolean value is: " + bool);
}
 
开发者ID:Driveron,项目名称:Notes,代码行数:47,代码来源:InputAllBaseTypes.java


注:本文中的java.util.Scanner.nextBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。