本文整理汇总了Java中java.util.Scanner.nextByte方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.nextByte方法的具体用法?Java Scanner.nextByte怎么用?Java Scanner.nextByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Scanner
的用法示例。
在下文中一共展示了Scanner.nextByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Byte n = in.nextByte();
double ans = 0;
double a[] = new double[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
Arrays.sort(a);
ans = a[a.length - 1];
for (int i = a.length - 1; i > 0; i--) {
ans = Max(ans, a[i - 1]);
}
System.out.printf("%.2f", ans);
}
示例2: 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);
}