public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! \n 3 + 3.0 = 6.0 true ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// print the next line
System.out.println("" + scanner.nextLine());
// print the next line again
System.out.println("" + scanner.nextLine());
// close the scanner
scanner.close();
}
}
public class GFG1 {
public static void main(String[] argv) throws Exception {
String s = "Gfg \n Geeks \n GeeksForGeeks";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print the next line
System.out.println(scanner.nextLine());
// print the next line again
System.out.println(scanner.nextLine());
// print the next line again
System.out.println(scanner.nextLine());
scanner.close();
}
}
public class ScannerNextLine {
public static void main(String[] args) throws FileNotFoundException {
// Declare File object
File file = new File("E:/tmp/java/tutorial/scanner/example.txt");
// initialize the scanner
Scanner scan = new Scanner(file);
// iterate through the file line by line
while(scan.hasNextLine()){
// print the contents of a file by line
System.out.println(scan.nextLine());
}
// close the scanner object;
scan.close();
}
}
public class ScannerNextLineExample1 {
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.print("Enter Item ID: ");
String itemID = scan.nextLine();
System.out.print("Enter Item price: ");
String priceStr = scan.nextLine();
double price = Double.valueOf(priceStr);
System.out.println("Price of Item "+itemID + " is $"+price);
scan.close();
}
}
class I1{
public static void main(String[] args){
Scanner s1 = new Scanner(System.in);
System.out.println("Enter an integer");
int a;
a = s1.nextInt();
System.out.println("The entered integer is" + n);
}
}
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();
}
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() + " ");
}
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"));
}
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();
}
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;
}