nextLong ( )源码实例Demo

java.util.Scanner#nextLong ( )源码实例Demo

下面列出了java.util.Scanner#nextLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: visualvm   文件: HeapHistogramImpl.java
HeapHistogramImpl(String histogramText) {
    Map<String,ClassInfoImpl> classesMap = new HashMap(1024);
    Map<String,ClassInfoImpl> permGenMap = new HashMap(1024);
    time = new Date();
    Scanner sc = new Scanner(histogramText);
    sc.useRadix(10);
    while(!sc.hasNext("-+")) {
        sc.nextLine();
    }
    sc.skip("-+");
    sc.nextLine();


    while(sc.hasNext("[0-9]+:")) {  // NOI18N
        ClassInfoImpl newClInfo = new ClassInfoImpl(sc);
        storeClassInfo(newClInfo, classesMap);
        totalHeapBytes += newClInfo.getBytes();
        totalHeapInstances += newClInfo.getInstancesCount();
    }
    sc.next("Total");   // NOI18N
    totalInstances = sc.nextLong();
    totalBytes = sc.nextLong();
    classes = new HashSet(classesMap.values());
}
 
源代码2 项目: AlgoCS   文件: Taxi_1607.java
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);
}
 
源代码3 项目: Universal-FE-Randomizer   文件: DiffCompiler.java
public void addDiffsFromFile(String diffName, long addressOffset) throws IOException {
	InputStream stream = DiffApplicator.class.getClassLoader().getResourceAsStream(diffName + ".diff");
	BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
	String currentLine = bufferedReader.readLine();
	while(currentLine != null) {
		Scanner scanner = new Scanner(currentLine);
		scanner.useDelimiter("[\\s\\W]+");
		long nextAddress = scanner.nextLong(16);
		int existingValue = scanner.nextInt(16);
		int newValue = scanner.nextInt(16);
		
		addDiff(new Diff(nextAddress + addressOffset, 1, new byte[] {(byte)(newValue & 0xFF)}, new byte[] {(byte)(existingValue & 0xFF)}));
		scanner.close();
		currentLine = bufferedReader.readLine();
	}
	
	stream.close();
}
 
源代码4 项目: ctsms   文件: DepartmentManager.java
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();
	}
}
 
源代码5 项目: AlgoCS   文件: TitanRuins_1910.java
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));
}
 
/** Main method */
public static void main(String[] args) {
	// Create a Scanner
	Scanner input = new Scanner(System.in);

	// Prompt the user to enter an integer
	System.out.print("Enter an integer: ");
	long n = input.nextLong();

	// Display the sum
	System.out.println("The sum of " + n + " = " + sumDigits(n));
}
 
源代码7 项目: sherlock   文件: NumberUtils.java
/**
 * @param str string to check
 * @return whether the string is a long value
 */
public static boolean isLong(String str) {
    if (str == null) {
        return false;
    }
    Scanner s = new Scanner(str.trim());
    if (!s.hasNextLong()) {
        return false;
    }
    s.nextLong();
    return !s.hasNext();
}
 
/** Main Method */
public static void main(String[] args) {
	Scanner input = new Scanner(System.in); // Create a Scanner

	// Prompt the user to enter an integer
	System.out.print("Enter a number: ");
	long number = input.nextLong();

	// Display the square root
	System.out.println(
		"The approximated square root of " + number + " is: " + sqrt(number));
}
 
源代码9 项目: db   文件: DataCubeColumn.java
/**
 *
 * @param val
 * @return
 * @throws IllegalArgumentException
 */
public Object interpret(Object val) throws IllegalArgumentException {
    String s = val.toString();
    Scanner sc = new Scanner(s);
    return sc.hasNextLong() ? sc.nextLong()
            : sc.hasNextInt() ? sc.nextInt()
            : sc.hasNextDouble() ? sc.nextDouble()
            : sc.hasNextBoolean() ? sc.nextBoolean()
            : sc.hasNextBigInteger() ? sc.nextBigInteger()
            : sc.hasNextFloat() ? sc.nextFloat()
            : sc.hasNextByte() ? sc.nextByte()
            : sc.hasNext() ? sc.next()
            : s;
}
 
源代码10 项目: db   文件: DataCubeDimension.java
/**
 *
 * @param val
 * @return
 * @throws IllegalArgumentException
 */
public Object interpret(Object val) throws IllegalArgumentException {
    String s = val.toString();
    Scanner sc = new Scanner(s);
    return sc.hasNextLong() ? sc.nextLong()
            : sc.hasNextInt() ? sc.nextInt()
            : sc.hasNextDouble() ? sc.nextDouble()
            : sc.hasNextBoolean() ? sc.nextBoolean()
            : sc.hasNextBigInteger() ? sc.nextBigInteger()
            : sc.hasNextFloat() ? sc.nextFloat()
            : sc.hasNextByte() ? sc.nextByte()
            : sc.hasNext() ? sc.next()
            : s;
}
 
源代码11 项目: db   文件: SchemaBuilder.java
public Object interpret(Object val) throws IllegalArgumentException {
    String s = val.toString();
    Scanner sc = new Scanner(s);

    return sc.hasNextInt() ? sc.nextInt()
            : sc.hasNextLong() ? sc.nextLong()
            : sc.hasNextDouble() ? sc.nextDouble()
            : sc.hasNextBoolean() ? sc.nextBoolean()
            : sc.hasNextBigInteger() ? sc.nextBigInteger()
            : sc.hasNextFloat() ? sc.nextFloat()
            : sc.hasNextByte() ? sc.nextByte()
            : sc.hasNext() ? sc.next()
            : s;
}
 
源代码12 项目: Intro-to-Java-Programming   文件: Exercise_06_02.java
/** Main Method */
public static void main(String[] args) {
	Scanner input = new Scanner(System.in); // Create a Scanner

	// Prompt the user to enter an integer
	System.out.print("Enter a integer: ");
	long number = input.nextLong();

	// Display the sum of all the digits in the integer
	System.out.println("The sum of the digits in " + number + " is " +
		sumDigits(number));
}
 
源代码13 项目: interviews   文件: LargestPrimeDivisor.java
public static void main(String[] args) {
	Scanner input = new Scanner(System.in);
	long number = input.nextLong();
	while (number != 0) {
		number = (long) (Math.abs(number));
		long largestPrimeDivisor = -1;
		int numberOfPrimeDivisors = 0;
		int sqrtOfNumber = (int) (Math.sqrt(number));
		for (int i = 2; i <= sqrtOfNumber; i++) {
			if (number % i == 0) {
				numberOfPrimeDivisors++;
				largestPrimeDivisor = i;
				while (number % i == 0) {
					number = number / i;
				}
			}
		}
		if (largestPrimeDivisor != -1 && number != 1) {
			System.out.println(number);
		} else if (numberOfPrimeDivisors <= 1) {
			System.out.println(-1);
		} else {
			System.out.println(largestPrimeDivisor);
		}
		number = input.nextLong();
	}
}
 
源代码14 项目: Hackerrank-Solutions   文件: StrangeCounter.java
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	long n = sc.nextLong();
	long i = 0;
	long lValue = (long) (3 * Math.pow(2, i)) - 2;
	long hValue = 2 * lValue + 1;

	while (hValue < n) {
		lValue = (long) (3 * Math.pow(2, ++i)) - 2;
		hValue = 2 * lValue + 1;
	}
	System.out.println(hValue + 1 - n);
	sc.close();
}
 
源代码15 项目: Hackerrank-Solutions   文件: AVeryBigSum.java
public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int n = in.nextInt();
	long sum = 0;

	for (int arr_i = 0; arr_i < n; arr_i++) {
		sum += in.nextLong();
	}
	System.out.println(sum);
	in.close();

}
 
源代码16 项目: visualvm   文件: HeapHistogramImpl.java
ClassInfoImpl(Scanner sc) {
    String jvmName;

    sc.next();
    instances = sc.nextLong();
    bytes = sc.nextLong();
    jvmName = sc.next();
    sc.nextLine();  // skip module name on JDK 9
    name = convertJVMName(jvmName);
}
 
源代码17 项目: Intro-to-Java-Programming   文件: Exercise_06_25.java
public static void main(String[] args) {
	Scanner input = new Scanner(System.in); // Create a scanner

	// Prompt the user to enter milliseconds
	System.out.print("Enter milliseconds: ");
	long millis = input.nextLong();

	// Convert milliseconds to hours, minutes, and seconds
	System.out.println("hours:minuties:seconds: " + convertMillis(millis));
}
 
源代码18 项目: UVA   文件: 10755 Garbage Heap.java
public static void main (String [] args) throws Exception {
	Scanner sc=new Scanner(System.in);
	int testCaseCount=sc.nextInt();
	for (int testCase=0;testCase<testCaseCount;testCase++) {
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		
		long [][][] v=new long [a][b][c];
		for (int i=0;i<a;i++) for (int i2=0;i2<b;i2++) for (int i3=0;i3<c;i3++) v[i][i2][i3]=sc.nextLong();
		
		long [][][] dp=new long [a][b][c];
		for (int i=0;i<a;i++) for (int i2=0;i2<b;i2++) for (int i3=0;i3<c;i3++) {
			dp[i][i2][i3]=v[i][i2][i3];
			if (i>0) dp[i][i2][i3]+=dp[i-1][i2][i3];
			if (i2>0) dp[i][i2][i3]+=dp[i][i2-1][i3];
			if (i3>0) dp[i][i2][i3]+=dp[i][i2][i3-1];
			
			if (i>0 && i2>0) dp[i][i2][i3]-=dp[i-1][i2-1][i3];
			if (i2>0 && i3>0) dp[i][i2][i3]-=dp[i][i2-1][i3-1];
			if (i>0 && i3>0) dp[i][i2][i3]-=dp[i-1][i2][i3-1];
			
			if (i>0 && i2>0 && i3>0) dp[i][i2][i3]+=dp[i-1][i2-1][i3-1];
		}
		
		long max=Long.MIN_VALUE;
		for (int i=0;i<a;i++) for (int i2=0;i2<b;i2++) for (int i3=0;i3<c;i3++) {
			for (int j=i;j<a;j++) for (int j2=i2;j2<b;j2++) for (int j3=i3;j3<c;j3++) {
				long curr=dp[j][j2][j3];
				
				if (i>0) curr-=dp[i-1][j2][j3];
				if (i2>0) curr-=dp[j][i2-1][j3];
				if (i3>0) curr-=dp[j][j2][i3-1];
				
				if (i>0 && i2>0) curr+=dp[i-1][i2-1][j3];
				if (i2>0 && i3>0) curr+=dp[j][i2-1][i3-1];
				if (i>0 && i3>0) curr+=dp[i-1][j2][i3-1];
				
				if (i>0 && i2>0 && i3>0) curr-=dp[i-1][i2-1][i3-1];

				max=Math.max(curr, max);
			}
		}
		
		if (testCase>0) System.out.println();
		System.out.println(max);
	}
}
 
源代码19 项目: localization_nifi   文件: AvroRecordConverter.java
/**
 * Converts the data from one schema to another. If the types are the same,
 * no change will be made, but simple conversions will be attempted for
 * other types.
 *
 * @param content
 *            The data to convert, generally taken from a field in an input
 *            Record.
 * @param inputSchema
 *            The schema of the content object
 * @param outputSchema
 *            The schema to convert to.
 * @return The content object, converted to the output schema.
 * @throws AvroConversionException
 *             When conversion is impossible, either because the output type
 *             is not supported or because numeric data failed to parse.
 */
private Object convertData(Object content, Schema inputSchema,
        Schema outputSchema) throws AvroConversionException {
    if (content == null) {
        // No conversion can happen here.
        if (supportsNull(outputSchema)) {
            return null;
        }
        throw new AvroConversionException("Output schema " + outputSchema
                + " does not support null");
    }

    Schema nonNillInput = getNonNullSchema(inputSchema);
    Schema nonNillOutput = getNonNullSchema(outputSchema);
    if (nonNillInput.getType().equals(nonNillOutput.getType())) {
        return content;
    } else {
        if (nonNillOutput.getType() == Schema.Type.STRING) {
            return content.toString();
        }

        // For the non-string cases of these, we will try to convert through
        // string using Scanner to validate types. This means we could
        // return questionable results when a String starts with a number
        // but then contains other content
        Scanner scanner = new Scanner(content.toString());
        scanner.useLocale(locale);
        switch (nonNillOutput.getType()) {
        case LONG:
            if (scanner.hasNextLong()) {
                return scanner.nextLong();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to long");
            }
        case INT:
            if (scanner.hasNextInt()) {
                return scanner.nextInt();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to int");
            }
        case DOUBLE:
            if (scanner.hasNextDouble()) {
                return scanner.nextDouble();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to double");
            }
        case FLOAT:
            if (scanner.hasNextFloat()) {
                return scanner.nextFloat();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to float");
            }
        default:
            throw new AvroConversionException("Cannot convert to type "
                    + nonNillOutput.getType());
        }
    }
}
 
源代码20 项目: nifi   文件: AvroRecordConverter.java
/**
 * Converts the data from one schema to another. If the types are the same,
 * no change will be made, but simple conversions will be attempted for
 * other types.
 *
 * @param content
 *            The data to convert, generally taken from a field in an input
 *            Record.
 * @param inputSchema
 *            The schema of the content object
 * @param outputSchema
 *            The schema to convert to.
 * @return The content object, converted to the output schema.
 * @throws AvroConversionException
 *             When conversion is impossible, either because the output type
 *             is not supported or because numeric data failed to parse.
 */
private Object convertData(Object content, Schema inputSchema,
        Schema outputSchema) throws AvroConversionException {
    if (content == null) {
        // No conversion can happen here.
        if (supportsNull(outputSchema)) {
            return null;
        }
        throw new AvroConversionException("Output schema " + outputSchema
                + " does not support null");
    }

    Schema nonNillInput = getNonNullSchema(inputSchema);
    Schema nonNillOutput = getNonNullSchema(outputSchema);
    if (nonNillInput.getType().equals(nonNillOutput.getType())) {
        return content;
    } else {
        if (nonNillOutput.getType() == Schema.Type.STRING) {
            return content.toString();
        }

        // For the non-string cases of these, we will try to convert through
        // string using Scanner to validate types. This means we could
        // return questionable results when a String starts with a number
        // but then contains other content
        Scanner scanner = new Scanner(content.toString());
        scanner.useLocale(locale);
        switch (nonNillOutput.getType()) {
        case LONG:
            if (scanner.hasNextLong()) {
                return scanner.nextLong();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to long");
            }
        case INT:
            if (scanner.hasNextInt()) {
                return scanner.nextInt();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to int");
            }
        case DOUBLE:
            if (scanner.hasNextDouble()) {
                return scanner.nextDouble();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to double");
            }
        case FLOAT:
            if (scanner.hasNextFloat()) {
                return scanner.nextFloat();
            } else {
                throw new AvroConversionException("Cannot convert "
                        + content + " to float");
            }
        default:
            throw new AvroConversionException("Cannot convert to type "
                    + nonNillOutput.getType());
        }
    }
}