Java Code Examples for java.util.Scanner.nextLine()

The following are Jave code examples for showing how to use nextLine() of the java.util.Scanner class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BankAccount_PasaskevakosG_BootCamp3   File: LoginScreen.java   View Source Code Vote up 8 votes
/**
 * 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();
}
 
Example 2
Project: codeforces   File: Problem_721A.java   View Source Code Vote up 7 votes
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() + " ");
}
 
Example 3
Project: RLibrary   File: IDCardUtil.java   View Source Code Vote up 7 votes
/**
 * @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"));
}
 
Example 4
Project: JavaCommon   File: StringBigNumberMulti.java   View Source Code Vote up 7 votes
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);

}
 
Example 5
Project: JavaRushTasks   File: Solution.java   View Source Code Vote up 7 votes
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();
}
 
Example 6
Project: Shield   File: Functions.java   View Source Code Vote up 7 votes
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;
    }
 
Example 7
Project: modern.core.java.repo   File: Computer.java   View Source Code Vote up 7 votes
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();
}
 
Example 8
Project: HackerRank-Studies   File: Solution.java   View Source Code Vote up 6 votes
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());
}
 
Example 9
Project: modern.core.java.repo   File: Passanger.java   View Source Code Vote up 6 votes
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);
}
 
Example 10
Project: Progetto-J   File: HumanTestStrategy.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 11
Project: SoftUni   File: p09_MatchFullName.java   View Source Code Vote up 6 votes
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();
    }

}
 
Example 12
Project: polyevent   File: Emission.java   View Source Code Vote up 6 votes
public void run() {
	
	  sc = new Scanner(System.in);
	  
	  while(true){
		    System.out.println("Votre message :");
			message = sc.nextLine();
			out.println(message);
		    out.flush();
		  }
}
 
Example 13
Project: ACE_HackerRank   File: Solution.java   View Source Code Vote up 6 votes
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);
}
 
Example 14
Project: HackerRank-Studies   File: Solutions.java   View Source Code Vote up 6 votes
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());
	}
 
Example 15
Project: codeforces   File: Problem_313A.java   View Source Code Vote up 6 votes
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));
    }
}
 
Example 16
Project: util4j   File: NodeMap.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
		byte[] data=new byte[1024*1024*1];
		for(int i=0;i<data.length;i++)
		{
			data[i]=(byte) RandomUtils.nextInt(255);
		}
		Scanner sc=new Scanner(System.in);
//		sc.nextLine();
//		new Test().testMap(data);
		sc.nextLine();
		Test t=new Test();
		t.testNMap(data);
		sc.nextLine();
	}
 
Example 17
Project: PatProject   File: Prob1043.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    Scanner scanner=new Scanner(System.in);
    String str=scanner.nextLine();

}
 
Example 18
Project: JavaRushTasks   File: ConsoleReader.java   View Source Code Vote up 5 votes
public static String readString() throws Exception {
    //напишите тут ваш код
    Scanner sc = new Scanner(System.in);
    return sc.nextLine();

}
 
Example 19
Project: modern.core.java.repo   File: Customer_class.java   View Source Code Vote up 4 votes
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    
    System.out.println("Hello Welcome to phoneDealership");
  
    Scanner takefromconsole = new Scanner(System.in);
    System.out.println("What phone are you after?");
     
  
     String phone = takefromconsole.nextLine();
    
     PhoneDealership_Class attendant = new PhoneDealership_Class();
     attendant.sellphones(phone);
}
 
Example 20
Project: hack   File: BasicsOfInputOutput.java   View Source Code Vote up 4 votes
public static void main(String args[] ) throws Exception {
    Scanner in = new Scanner(System.in);

    int n = in.nextInt();

    System.out.println(n * 2);

    in.nextLine();

    System.out.println(in.nextLine());
}