guys, let's say I have a file that contains
1
33
b s
4
10
f
a
120
5 6
I want to count the numbers and letters, in my code I'm using the Character.isDigit(String.chartat(0)) to identify the numbers. But you can only use nextInt(); to read the input. this is very straight forward using next(), but how could I do it using nextInt();
public static void main(String[] args) { mixedF(); } public static void mixedF() { int numbers = 0; int words = 0; String ch; try { Scanner in = new Scanner(new File("myFile.txt")); while(in.hasNext()) { ch = in.next(); if(Character.isDigit(ch.charAt(0))) numbers++; else words++; } System.out.println("numbrers: "+numbers); System.out.println("words: "+words); } catch (FileNotFoundException ex) { ex.getMessage(); } }