Results 1 to 8 of 8
Thread: how add parse in scanner
- 01-15-2010, 04:02 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 12
- Rep Power
- 0
how add parse in scanner
how add parse in scanner
this is code take if statement and split to types
and i want to add to code parse
where check if statement that is in code with if correct statement and know do it is correct or no ?
plz anyone help me and thank you
Java Code:import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String args[]) throws IOException { int i; double d; boolean b; String str; String str1; String str2; String str3; String str4; String str5; FileWriter fout = new FileWriter("test.txt"); fout.write("if int a = 30 int c = a / 5 ;"); fout.close(); FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { i = src.nextInt(); System.out.println("int: " + i); } else if (src.hasNextDouble()) { d = src.nextDouble(); System.out.println("double: " + d); } else if (src.hasNextBoolean()) { b = src.nextBoolean(); System.out.println("boolean: " + b); } else if (src.hasNext("if")){ str = src.next("if"); System.out.println("Resrved words: " + str); } else if (src.hasNext("=")){ str1 = src.next("="); System.out.println("Compute: " + str1); } else if (src.hasNext(";")){ str2 = src.next(";"); System.out.println("Compute: " + str2); } else if (src.hasNext("/")){ str2 = src.next("/"); System.out.println("Compute: " + str2); } /*else if (src.hasNext("(")){ str3 = src.next("("); System.out.println("Compute: " + str3); } else if (src.hasNext(")")){ str4 = src.next(")"); System.out.println("Compute: " + str4); }*/ else if (src.hasNext("==")){ str5 = src.next("=="); System.out.println("Logical: " + str5); } else if (src.hasNext("==")){ str5 = src.next("=="); System.out.println("Logical: " + str5); } else { str = src.next(); System.out.println("Variables: " + str); } } fin.close(); } }
- 01-15-2010, 04:23 AM #2
src.findInLine("if")
hi
you can use
src.findInLine("if")
to get if
src.findInLine("int")
to get int etc.....
please refer
Scanner (Java 2 Platform SE 5.0)
- 01-15-2010, 04:50 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 12
- Rep Power
- 0
thank you for helping
but i want to check on "if" in first then "int" then "a" or any word except a ...etc
thnks
- 01-15-2010, 04:52 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Also at bytes.com
- 01-15-2010, 04:56 AM #5
Member
- Join Date
- Oct 2009
- Posts
- 12
- Rep Power
- 0
-
Yes, cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.
Hopefully, but again being upfront about the cross-posting will help increase your odds.there is anyone reply me
Edit: Also if possible, please edit your questions. For some reason, they seem difficult for me to understand. I assume that English is not your native language. Am I correct?
Much luck.Last edited by Fubarable; 01-15-2010 at 05:07 AM.
- 01-15-2010, 05:07 AM #7
Member
- Join Date
- Oct 2009
- Posts
- 12
- Rep Power
- 0
- 01-15-2010, 05:18 AM #8
Member
- Join Date
- Oct 2009
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
using parse
By mustachMan in forum New To JavaReplies: 2Last Post: 01-15-2010, 01:32 AM -
Use Scanner to parse text file, adding to HashMap
By JordashTalon in forum New To JavaReplies: 0Last Post: 03-04-2009, 11:08 PM -
SAX Parse
By bluefloyd8 in forum New To JavaReplies: 1Last Post: 01-25-2008, 03:57 PM -
How to parse in html
By paty in forum New To JavaReplies: 1Last Post: 07-24-2007, 12:29 AM -
Parse error
By Eric in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 06:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks