How many lexemes does the following Java code contain? Give the number of lexeme
ID: 3788205 • Letter: H
Question
How many lexemes does the following Java code contain?
Give the number of lexemes on each line (using the line numbers shown) as well as the total number of lexemes.
public class CountDigits {
public static void main(String[] args) {
SimpleIO.prompt("Enter an integer: ");
String userInput = SimpleIO.readLine();
int number = Integer.parseInt(userInput);
int numDigits = 0;
while (number > 0) {
number /= 10;
numDigits++;
}
System.out.println("The number " + userInput + " has " +
numDigits + " digits");
}
}
Explanation / Answer
Note:
I provided some space between each lexeme to make you understand.Thank You
________________________
1)public class CountDigits {
2) public static void main ( String [ ] args ) {
3) SimpleIO . prompt ( "Enter an integer: " ) ;
4) String userInput = SimpleIO . readLine ( ) ;
5) int number = Integer . parseInt ( userInput ) ;
6) int numDigits = 0 ;
7) while ( number > 0 ) {
8) number /= 10 ;
9) numDigits ++ ;
10) }
11) System . out . println ( "The number " + userInput + " has " +
12) numDigits + " digits" ) ;
13) }
14) }
Lexemes in each line:
1) 4
2) 11
3) 7
4) 9
5) 10
6) 5
7) 7
8) 5
9) 3
10) 1
11)
12)17
13) 1
14) 1
__________
Total no of lexemes is : 81
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.