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


Java Scanner.nextLong方法代码示例

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


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

示例1: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long a, b, x, y, i = 0;
    a = in.nextLong();
    x = in.nextLong();
    b = in.nextLong();
    y = in.nextLong();
    if (a >= b) {
        System.out.println(a);
        return;
    }
    while (a <= b) {
        if (a + x >= b) {
            System.out.println(b);
            return;
        }
        a += x;
        b -= y;
    }
    System.out.println(a);
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:22,代码来源:Taxi_1607.java

示例2: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    long min = Long.MAX_VALUE;

    long max = Long.MIN_VALUE;

    long sum = 0;

    long tmp;
    while(in.hasNextLong()) {
        tmp = in.nextLong();

        if (tmp < min) {
            min = tmp;
        }

        if (tmp > max) {
            max = tmp;
        }

        sum += tmp;
    }

    System.out.println((sum - max) + " " + (sum - min));
}
 
开发者ID:viatsko,项目名称:hack,代码行数:27,代码来源:MiniMaxSum.java

示例3: interactiveChangeDepartmentPassword

import java.util.Scanner; //导入方法依赖的package包/类
public void interactiveChangeDepartmentPassword() {
	Scanner in = ExecUtil.getScanner();
	try {
		printDepartments();
		System.out.print("enter department id for department password change:");
		long departmentId = in.nextLong();
		in.nextLine();
		String plainOldDepartmentPassword = ExecUtil.readPassword(in, "enter current department password:");
		printDepartmentPasswordPolicy();
		String plainNewDepartmentPassword = readConfirmedPassword(in, "enter new department password:", "confirm new department password:");
		if (ExecUtil.confirmationPrompt(in, "ready.")) {
			toolsService.changeDepartmentPassword(departmentId, plainNewDepartmentPassword, plainOldDepartmentPassword);
			System.out.println("department password change successful");
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		in.close();
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:21,代码来源:DepartmentManager.java

示例4: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int t = scan.nextInt();
    for (int i = 0; i < t; i++) {
        try {
            long x = scan.nextLong();
            System.out.println(x + " can be fitted in:");
            if (x >= Byte.MIN_VALUE && x <= Byte.MAX_VALUE) {
                System.out.println("* byte");
            }
            if (x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) {
                System.out.println("* short");
            }
            if (x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE) {
                System.out.println("* int");
            }
            if (x >= Long.MIN_VALUE && x <= Long.MAX_VALUE) {
                System.out.println("* long");
            }
        } catch (Exception e) {
            System.out.println(scan.next() + " can't be fitted anywhere.");
        }
    }
    scan.close();
}
 
开发者ID:rshaghoulian,项目名称:HackerRank_solutions,代码行数:26,代码来源:Solution.java

示例5: interactiveCreateUser

import java.util.Scanner; //导入方法依赖的package包/类
public void interactiveCreateUser() {
	Scanner in = ExecUtil.getScanner();
	try {
		printDepartments();
		System.out.print("enter department id for new user:");
		Long departmentId = in.nextLong();
		in.nextLine();
		String plainDepartmentPassword = ExecUtil.readPassword(in, "enter department password:");
		System.out.print("enter new username:");
		String username = in.nextLine();
		System.out.print("enter user language [" + getDefaultLocale() + "]:");
		UserInVO newUser = getNewUser(departmentId, username, in.nextLine());
		printPasswordPolicy();
		PasswordInVO newPassword = getNewPassword(ExecUtil.readPassword(in, "enter desired user password:"));
		printPermissionProfiles();
		System.out.print("enter separated list of permission profiles:");
		ArrayList<PermissionProfile> profiles = checkProfileList(in.nextLine());
		UserOutVO user = toolsService.addUser(newUser, newPassword, plainDepartmentPassword);
		System.out.println("user created");
		addUserPermissionProfiles(user, profiles);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		in.close();
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:27,代码来源:DepartmentManager.java

示例6: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long n = in.nextLong(), x = 0, max = 0, s = 0;
    int a[] = new int[(int) n];
    for (int i = 0; i < a.length; i++) {
        a[i] = in.nextInt();
    }
    if (n >= 3) {
        for (int i = 1; i < a.length - 1; i++) {
            s = a[i] + a[i - 1] + a[i + 1];
            if (s > max) {
                max = s;
                x = i;
            }
        }
    }
    System.out.print(max + " " + (x + 1));
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:19,代码来源:TitanRuins_1910.java

示例7: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long input = in.nextLong();
    long result = 0;

    if (input < 10) {
        for (int i = 1; i <= input; i++)
            result += sign(i);
    } else {
        if (input % 2 == 1)
            result = (input / 2 + 1) * (-1);
        else
            result = input / 2;
    }

    System.out.print(result);
}
 
开发者ID:AlbertHambardzumyan,项目名称:codeforces,代码行数:18,代码来源:Problem_486A.java

示例8: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long sum = 0;
    long min = Integer.MAX_VALUE;
    long max = Integer.MIN_VALUE;
    for (int i = 0; i < 5; i++) {
        long num = scan.nextLong();
        sum += num;
        min = Math.min(min, num);
        max = Math.max(max, num);
    }
    scan.close();
    System.out.print((sum - max) + " " + (sum - min));
}
 
开发者ID:rshaghoulian,项目名称:HackerRank_solutions,代码行数:15,代码来源:Solution.java

示例9: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int T = scan.nextInt();
    while (T-- > 0) {
        long B = scan.nextLong();
        long W = scan.nextLong();
        long X = scan.nextLong();
        long Y = scan.nextLong();
        long Z = scan.nextLong();
        long priceB = Math.min(X, Y + Z); // conversion price
        long priceW = Math.min(Y, X + Z); // conversion price
        System.out.println(B * priceB + W * priceW);
    }
    scan.close();
}
 
开发者ID:rshaghoulian,项目名称:HackerRank_solutions,代码行数:16,代码来源:Solution.java

示例10: 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

示例11: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long a = in.nextLong();
    long b = in.nextLong();

    System.out.print(compute(a, b));
}
 
开发者ID:AlbertHambardzumyan,项目名称:codeforces,代码行数:8,代码来源:Problem_527A.java

示例12: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    /* Save input */
    Scanner scan = new Scanner(System.in);
    String str = scan.next();
    long n     = scan.nextLong();
    scan.close();
    
    /* Found out # of times 'a' appears in our String */
    int wordAs = 0;
    for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) == 'a') {
            wordAs++;
        }
    }

    long completeWords    = n / str.length();
    long remainingLetters = n % str.length();
    long totalAs          = completeWords * wordAs;
    
    /* Count up the remaining 'a' characters */
    for (int i = 0; i < remainingLetters; i++) {
        if (str.charAt(i) == 'a') {
            totalAs++;
        }
    }
    
    System.out.println(totalAs);
}
 
开发者ID:MohamedSondo,项目名称:ACE_HackerRank,代码行数:29,代码来源:Solution.java

示例13: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long input = in.nextLong();

    boolean result = lucky_counter(input);
    System.out.print(result ? "YES" : "NO");
}
 
开发者ID:AlbertHambardzumyan,项目名称:codeforces,代码行数:8,代码来源:Problem_110A.java

示例14: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] box = new int[10];
        if (true) {

            long a = scanner.nextLong();
            //        long temp=0L;
            //        int tempb=0;
            while (a != 0L) {
                long temp = a % 10L;
                int tempb = (int) temp;
                box[tempb]++;
                a = a / 10;
            }
        } else {
            char[] chars = scanner.nextLine().toCharArray();
            for (char i : chars) {
                box[Integer.parseInt(i + "")]++;
            }
        }

//

        int lenOfBox = box.length;
        for (int i = 0; i < lenOfBox; i++) {
            if (box[i] != 0) {
                System.out.println(i + ":" + box[i]);
            }
        }
    }
 
开发者ID:Philippian,项目名称:PatProject,代码行数:31,代码来源:Prob1021.java

示例15: main

import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long timeResult = Math.round((b - a) / 100.0);
        System.out.printf("%02d:%02d:%02d", timeResult / 3600, (timeResult / 60) % 60, timeResult % 60);
//        System.out.print(+":"++":"+);
    }
 
开发者ID:Philippian,项目名称:PatProject,代码行数:9,代码来源:Prob1026.java


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