本文整理汇总了Java中java.util.Scanner.nextLine方法的典型用法代码示例。如果您正苦于以下问题:Java Scanner.nextLine方法的具体用法?Java Scanner.nextLine怎么用?Java Scanner.nextLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Scanner
的用法示例。
在下文中一共展示了Scanner.nextLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userCredentials
import java.util.Scanner; //导入方法依赖的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();
}
示例2: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
in.nextInt();
in.nextLine();
String input = in.nextLine();
LinkedList<Integer> list = new LinkedList<>();
int count = 0;
for (int i = 0; i < input.length(); i++) {
char tmp = input.charAt(i);
if (tmp == 'B') count++;
else if (count != 0) {
list.addLast(count);
count = 0;
}
}
if (count > 0) list.addLast(count);
System.out.println(list.size());
while (!list.isEmpty()) System.out.print(list.pollFirst() + " ");
}
示例3: main
import java.util.Scanner; //导入方法依赖的package包/类
/**
* @param args
* @throws ParseException
*/
@SuppressWarnings("static-access")
public static void main(String[] args) {
// String IDCardNum="210102820826411";
// String IDCardNum="210102198208264114";
while (true) {
Scanner input = new Scanner(System.in);
String n = input.nextLine();
if (n.equals("N") || n.equals("n")) {
break;
}
String IDCardNum = input.nextLine();
IDCardUtil cc = new IDCardUtil();
System.out.println(cc.IDCardValidate(IDCardNum));
}
// System.out.println(cc.isDate("1996-02-29"));
}
示例4: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
String[] values = line.trim().split(" ");
if (values.length != 2) {
return;
}
String str1 = values[0];
String str2 = values[1];
int len1 = str1.length();
int len2 = str2.length();
char[] s1 = str1.toCharArray();
char[] s2 = str2.toCharArray();
// 高低位对调
covertdata(s1, len1);
covertdata(s2, len2);
System.out.println("乘数:" + str1);
System.out.println("乘数:" + str2);
multiply(s1, len1, s2, len2);
}
示例5: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Scanner consoleReader = new Scanner(System.in);
FileInputStream f = new FileInputStream(consoleReader.nextLine());
int max = 0;
if (f.available() > 0)
max = f.read();
while (f.available() > 0) {
int value = f.read();
if (max < value)
max = value;
}
System.out.println(max);
f.close();
}
示例6: secondList
import java.util.Scanner; //导入方法依赖的package包/类
public static ArrayList<String[]> secondList(){
try{
Scanner scannerSongs = new Scanner(new File("Recommended_db.csv"));
ArrayList<String[]> allSongs = new ArrayList<>();
scannerSongs.nextLine();
while (scannerSongs.hasNextLine()) {
String line = scannerSongs.nextLine();
String[] columns = line.split(",");
String[] songInfo = {columns[3],columns[4],null};
allSongs.add(songInfo);
}
return allSongs;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例7: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
System.out.println("what laptop do you prefer?");
Scanner myScan = new Scanner(System.in);
String laptopType = myScan.nextLine();
laptop hp = new laptop();
System.out.println(hp.storage);
hp.storage = 1000;
hp.getInformation();
hp.storeRelevantData();
hp.watchVideos();
laptop mac = new laptop();
System.out.println(mac.storage);
mac.storage = 256;
mac.colour = "silver";
boolean laptop1 = mac.istouchScreen;
laptop dell = new laptop();
}
示例8: checker
import java.util.Scanner; //导入方法依赖的package包/类
public void checker(String Regex_Pattern){
Scanner Input = new Scanner(System.in);
String Test_String = Input.nextLine();
Pattern p = Pattern.compile(Regex_Pattern);
Matcher m = p.matcher(Test_String);
System.out.println(m.find());
}
示例9: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner myConsoleScanner = new Scanner(System.in);
System.out.println("Where are you traveling to ?");
String destination = myConsoleScanner.nextLine();
BusTicketStand standA = new BusTicketStand();
standA.sellTicket(destination);
}
示例10: act
import java.util.Scanner; //导入方法依赖的package包/类
/**
* Determina l'azione da eseguire
* @param minBet la puntata minima
* @param bet la puntata
* @param allowedActions le azioni consentite
* @return l'azione richiesta
*/
@Override
public Action act(int minBet, int bet, Set<ActionSet> allowedActions)
{
Action action = null;
System.out.println(this.toString() + " chiede di agire: ");
Scanner in = new Scanner(System.in);
if(in.hasNextLine())
{
do {
String result = in.nextLine();
String[] tokens = result.split(" ");
if (tokens[0].equalsIgnoreCase("H")) {
action = new Check();
}
if (tokens[0].equalsIgnoreCase("R")) {
action = new Raise(Integer.parseInt(tokens[1]));
}
if (tokens[0].equalsIgnoreCase("C")) {
action = new Call();
}
if (tokens[0].equalsIgnoreCase("T")) {
action = new Bet(Integer.parseInt(tokens[1]));
}
if (tokens[0].equalsIgnoreCase("B")) {
action = new BigBlind(0);
}
if (tokens[0].equalsIgnoreCase("S")) {
action = new SmallBlind(0);
}
if (tokens[0].equalsIgnoreCase("F")) {
action = new Fold();
}
} while (!allowedActions.contains(action.getActionType()));
}
return action;
}
示例11: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner scann = new Scanner(System.in);
String regex = "^[A-Z][a-z]+ [A-Z][a-z]+$";
String input = scann.nextLine();
while(!input.equals("end")){
if(Pattern.matches(regex, input))
System.out.println(input);
input = scann.nextLine();
}
}
示例12: run
import java.util.Scanner; //导入方法依赖的package包/类
public void run() {
sc = new Scanner(System.in);
while(true){
System.out.println("Votre message :");
message = sc.nextLine();
out.println(message);
out.flush();
}
}
示例13: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
/* Read input */
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
double d = scan.nextDouble();
scan.nextLine(); // gets rid of the pesky newline
String s = scan.nextLine();
scan.close();
/* Print output */
System.out.println("String: " + s);
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}
示例14: checker
import java.util.Scanner; //导入方法依赖的package包/类
public void checker(String Regex_Pattern){
Scanner Input = new Scanner(System.in);
String Test_String = Input.nextLine();
Pattern p = Pattern.compile(Regex_Pattern);
Matcher m = p.matcher(Test_String);
System.out.println(m.find());
}
示例15: main
import java.util.Scanner; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String input = in.nextLine();
if (Integer.parseInt(input) >= 0)
System.out.print(input);
else {
int temp1 = Integer.parseInt(input.substring(0, input.length() - 1));
int temp2 = Integer.parseInt(input.substring(0, input.length() - 2) + input.substring(input.length() - 1));
System.out.print(Math.max(temp1, temp2));
}
}