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


Java Scanner.nextLine方法代码示例

本文整理汇总了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();
}
 
开发者ID:GrigorisParaskevakos,项目名称:BankAccount_PasaskevakosG_BootCamp3,代码行数:20,代码来源:LoginScreen.java

示例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() + " ");
}
 
开发者ID:AlbertHambardzumyan,项目名称:codeforces,代码行数:22,代码来源:Problem_721A.java

示例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"));
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:22,代码来源:IDCardUtil.java

示例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);

}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:26,代码来源:StringBigNumberMulti.java

示例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();
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:17,代码来源:Solution.java

示例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;
    }
 
开发者ID:prakamya-mishra,项目名称:Shield,代码行数:20,代码来源:Functions.java

示例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();
}
 
开发者ID:cyber-coders-j2017a,项目名称:modern.core.java.repo,代码行数:21,代码来源:Computer.java

示例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());
}
 
开发者ID:jsong00505,项目名称:HackerRank-Studies,代码行数:8,代码来源:Solution.java

示例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);
}
 
开发者ID:cyber-coders-j2017a,项目名称:modern.core.java.repo,代码行数:10,代码来源:Passanger.java

示例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;
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-J,代码行数:44,代码来源:HumanTestStrategy.java

示例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();
    }

}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:13,代码来源:p09_MatchFullName.java

示例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();
		  }
}
 
开发者ID:antonin-arquey,项目名称:polyevent,代码行数:12,代码来源:Emission.java

示例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);
}
 
开发者ID:MohamedSondo,项目名称:ACE_HackerRank,代码行数:15,代码来源:Solution.java

示例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());
	}
 
开发者ID:jsong00505,项目名称:HackerRank-Studies,代码行数:9,代码来源:Solutions.java

示例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));
    }
}
 
开发者ID:AlbertHambardzumyan,项目名称:codeforces,代码行数:13,代码来源:Problem_313A.java


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