i've come up with this program from reading and researching.. (coz i'm just a newbie in
java and my program's kinda lame..) i can't seem to solve the problem here.. it has one error the last time i compiled it.. can someone pls help me with this? please.. tnx..
here's the program's conditions:
--> the program will ask the user for 10 input.. after the the user input something, the program needs to determine if the input's data type is an integer, a float, a character or a
string..
import java.awt.*;
import java.io.*;
import java.lang.*;
public class LexicalAnalyzer
{
public static boolean Letter(String s)
{
for (int e = 0; e < s.length()-1; e++)
{
char f = s.charAt(e);
if (Character.isLetter(f))
{if (s.length() == 1)
return true; }}
}
public static void main(String args[]) throws IOException
{
String anything, k;
double p = 0;
int a, q = 0, b;
char i, c;
//inputkoh
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
for(a=1 ; a<11 ; a++)
{
System.out.print("Input anything: ");
anything = input.readLine();
for (b = 0; b < anything.length; b++)
{c = anything.charAt(b);
if (Character.isDigit(c) && c != '.')
{p = Double.parseDouble(anything);
break; }
else if(c == '.')
{q = Integer.parseInt(anything);
break; } }
if (q == 0)
System.out.print("Input is Real");
else if (p == 0)
System.out.print("Input is an Integer");
if (Letter(anything))
System.out.print("Input is a Character");
else
System.out.print("Input is a String");
}}
[ January 22, 2004: Message edited by: Teresa Juan ]