Home Answers Viewqa Design-concepts-design-patterns Problems in Stringtokenizer

Have Programming Question? Ask it here!

Siba mishra
Problems in Stringtokenizer
0 Answer(s)      2 years and a month ago
Posted in : Design concepts & design patterns

```hi

here is my code

import java.util.*;
import java.io.*;
import java.util.Scanner;
class Node
{
public boolean marked;
public int node_no;
public String node_type;
//public float value;
//public float control_value;
public  String usevar[];
public String defvar[];
public int child[];
public int par[];
public int actIn[];
public int actOut[];
}
public class Input
{
public int n,nn,vn;                                 //vn total no of variables,    n total no of node ,nn  node no.
public int i,use_var,def_var,p_c,c_c;               //
public String c,f,var_nam[];
public Node node[];
StringTokenizer str,str1;
Input() throws Exception
{
Scanner fr=new Scanner(df);
str=new StringTokenizer(fr.nextLine(),"\$");
this.n=Integer.parseInt(str.nextToken());        //total no of nodes
this.vn=Integer.parseInt(str.nextToken());       //toal no of variables
var_nam=new String[vn];                         //for total variables
str=new StringTokenizer(fr.nextLine(),"\$");
System.out.println("rtryutrty"+n+vn);
for(int i=0;i<vn;i++)
{
String a=str.nextToken();
var_nam[i]=a;
}
node=new Node[n+1];
for(int i=1;i<=n;i++)
{
node[i]=new Node();
}
i=1;
while(fr.hasNextLine())
{
c=fr.nextLine();
str=new StringTokenizer(c,"\$");                         //node no is parsed
nn=Integer.parseInt(str.nextToken());
System.out.println(nn);
node[i].node_no=nn;                                 //node no is assigned

str1=new StringTokenizer(str.nextToken()," ");
use_var=str1.countTokens();                              // no of use var
node[i].usevar=new String[use_var];
for(int j=0;j<use_var;j++)
{
node[i].usevar[j]=str1.nextToken();
}
for(int j=0;j<use_var;j++)
{
System.out.println(node[i].usevar[j]);
}

str1=new StringTokenizer(str.nextToken()," ");      // for def var
def_var=str1.countTokens();
node[i].defvar=new String[def_var];
for(int j=0;j<def_var;j++)
{
node[i].defvar[j]=str1.nextToken();
}
for(int j=0;j<def_var;j++)
{
System.out.println(node[i].defvar[j]);
}

str1=new StringTokenizer(str.nextToken()," ");          // parents node info
p_c=str1.countTokens();
node[i].par=new int[p_c];
for(int j=0;j<p_c;j++)
{
node[i].par[j]=Integer.parseInt(str1.nextToken());
}
for(int j=0;j<p_c;j++)
{
System.out.println(node[i].par[j]);
}

System.out.println("erhiwe");
str1=new StringTokenizer(str.nextToken()," ");          // child node info
c_c=str1.countTokens();
node[i].child=new int[c_c];
for(int j=0;j<c_c;j++)
{
node[i].child[j]=Integer.parseInt(str1.nextToken());
}
for(int j=0;j<c_c;j++)
{
System.out.println(node[i].child[j]);
}
node[i].node_type=str.nextToken();   // node type
//System.out.println("sfdsrsr\n\n\n");
int temp=Integer.parseInt(str.nextToken());
System.out.println(temp);
node[i].actIn= new int[temp];
str1=new StringTokenizer(str.nextToken()," ");
for(int  temp1=0;str1.hasMoreTokens();temp1++)
node[i].actIn[temp1]=Integer.parseInt(str1.nextToken());        //total actIn are Obtained
temp=Integer.parseInt(str.nextToken());
System.out.println(temp);
node[i].actOut= new int[temp];
str1=new StringTokenizer(str.nextToken()," ");
for(int  temp1=0;str1.hasMoreTokens();temp1++)
node[i].actOut[temp1]=Integer.parseInt(str1.nextToken());                  //total actOut are Obtained

i++;                                                                            //next node
}
}

public static void main(String args[])throws Exception
{
Input i=new Input();
System.out.println("\nnew main\n");
for(int k=1;k<=i.n;k++)
{
//System.out.println("\nnew main\n");
System.out.print(i.node[k].marked);
System.out.print(i.node[k].node_no+" a121a ");
for(int j=0;j<i.node[k].usevar.length;j++)
System.out.print(i.node[k].usevar[j]+" ");
for(int j=0;j<i.node[k].defvar.length;j++)
System.out.print(i.node[k].defvar[j]+" ");
for(int j=0;j<i.node[k].child.length;j++)
System.out.print(i.node[k].child[j]+"  ");
for(int j=0;j<i.node[k].par.length;j++)
System.out.print(i.node[k].par[j]+"  ");
for(int j=0;j<i.node[k].actOut.length;j++)
System.out.print(i.node[k].actOut[j]+"  ");
for(int j=0;j<i.node[k].actIn.length;j++)
System.out.print(i.node[k].actIn[j]+"  ");
System.out.print(i.node[k].node_type+"  ");
System.out.println(" ");
}
}

}
```

When i am trying to compile the code i found the following error

Error: Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at Input.(Input.java:84) at Input.main(Input.java:130)

Actually this is an implementation of a slicing algorithm. The class Input.java specifies the Input to the program with the help of a text file. Below I am attaching the text file named Input.txt. the input file is too large in size. Please let me know more about the flaws.

```58\$14
57\$\$\$\$0\$58\$\$\$\$\$
58\$\$\$\$57\$59 60\$\$\$\$\$
59\$\$\$\$58\$6\$\$\$\$\$
60\$\$\$\$58\$33\$\$\$\$\$
6\$7 33 34\$7\$59\$7 8 9 10 12\$\$\$\$\$\$
33\$34 6 7\$34\$60\$67 34 35 36 37 38 39\$\$\$\$\$\$
7\$8 15 34 35\$7 34 \$6\$8\$\$\$\$\$\$
34\$35 7 8\$7 34\$33\$35\$\$\$\$\$\$
35\$36 37 5 7 9 10 14 15\$35\$33 34\$36 37\$\$\$\$\$\$
59\$\$\$\$58\$6\$\$\$\$\$
10\$\$8\$6 8 9\$11 14 17\$\$\$\$\$\$
8\$9 10 14 15 35 36 37\$8\$6 7\$10 15\$\$\$\$\$\$
9\$\$8 35\$6 8\$10 15\$\$\$\$\$\$
36\$\$8 35\$33 35\$37\$\$\$\$\$\$
37\$\$9 35\$6 8\$10 15\$\$\$\$\$\$
38\$\$\$33\$40\$\$\$\$\$\$
39\$\$\$33\$52\$\$\$\$\$\$
40\$\$\$37 38 69\$41 45 46 50\$\$\$\$\$\$
41\$47 48 50 51 70 71 72 74\$41\$40\$47 48\$\$\$\$\$\$
46\$47 49 45\$45\$40\$47 48 49 70\$\$\$\$\$\$
45\$49 45 46\$45\$40\$49\$\$\$\$\$\$
47\$48 45 46 49\$41\$41 45\$48 49\$\$\$\$\$\$
48\$47 49 45 46 70 71 72 74\$41\$41 46 47 50 51\$0\$\$\$\$\$\$
49\$47 49 45 46\$45\$45 46 47\$0\$\$\$\$\$\$
50\$51 41 48\$41\$40\$70 51 48\$\$\$\$\$\$
51\$41 48 50 51 71 72 74 70\$41\$40 50 75\$48\$\$\$\$\$\$
52\$\$\$49\$37 39\$53 54 55 56\$\$\$\$\$
53\$56\$53\$52\$56\$\$\$\$\$\$
54\$56 27 28 29\$54 27\$52 27\$56\$\$\$\$\$\$
55\$56 28 29\$55\$52 28\$56\$\$\$\$\$\$
56\$53 54 55 27 28 29\$53 54 55 27 28\$52 53 54 55\$0\$\$\$\$\$\$
11\$\$\$10\$26\$\$\$\$\$\$
12\$\$\$6 24 66\$13 16\$\$\$\$\$\$
13\$15\$13\$12\$14 15\$\$\$\$\$\$
14\$8 9 10 15 14 35 36 37\$8 35\$10 13\$15\$sleep node\$\$\$\$\$
15\$8 9 10 13 14 15 35 36 37\$8 35 13\$8 9 13 14\$16\$\$\$\$\$\$
16\$\$\$12 15\$0\$\$\$\$\$\$
17\$\$\$\$29 64 10\$19 23 24\$\$\$\$\$
19\$24\$19\$17\$24\$\$\$\$\$\$
23\$23 24 25\$\$17\$24\$\$\$\$\$\$
24\$19 23 24 25\$19\$17 19 23\$12 25\$\$\$\$\$\$
25\$23 24 25\$\$24\$65\$\$\$\$\$\$
26\$\$\$11\$27 28 29\$\$\$\$\$\$
27\$29 54 56\$27 54\$26\$29\$\$\$\$\$\$
28\$29 55 56\$28 55\$26\$29 55\$\$\$\$\$\$
29\$27 28 29 54 55 56\$27 28 54 55\$26 27 28\$17 62\$\$\$\$\$\$
62\$\$\$29\$63 65\$pointcut vertex\$\$\$\$\$
64\$\$\$63\$17\$\$\$\$\$\$
66\$\$\$65\$12\$\$\$\$\$\$
67\$\$\$33\$68 70\$poincut vertex\$\$\$\$\$
69\$\$\$68\$40\$\$\$\$\$\$
70\$71 72 74 41 48 50 70 51\$41\$46 50 67\$71 75 f1_in\$\$1\$f1_in\$\$\$ startingadvice vertex
71\$70 71 72 74 41 48 50 51\$41\$70\$72 74\$\$\$\$\$\$
72\$70 71 72 74 41 48 50 51\$41\$f1_in\$0\$\$\$\$\$\$
74\$70 71 72 74 41 48 50 51\$41\$71 f1_in\$0\$\$\$\$\$\$
75\$\$\$70\$51\$\$\$\$\$\$
```

The algorithm is as follows:

```import java.util.*;
class DynamicSlice
{
String var_name;
int par[];
DynamicSlice(int n)
{
par=new int[n+1];   //no of nodes is=n
}
}
class Algo extends Input
{
int zc=n+1;
DynamicSlice dn[][]=new DynamicSlice[zc][vn];
int rec_def[];
Algo() throws Exception
{}
public void init()
{
rec_def =new int[vn];
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
dn[i][j]=new DynamicSlice(n);
//set Dynamic slice is creATED
for(int i=1;i<n+1;i++)
for(int j=0;j<vn;j++)
{
dn[i][j].var_name=var_nam[j];
}
}
//variable name is assigned to each position

public int varat(String x)
{
for(int i=0;i<vn;i++)
if(x.equals(var_nam[i]))return(i);
return 0;
}   // knowing the position of var in vaiable list
public void a2(int nodeno)
{
for(int l=0; l<node[nodeno].usevar.length;l++)
{
int index = varat(node[nodeno].usevar[l]);
for(int i=1;i<n+1;i++){
int k=dn[nodeno][index].par[i];
if(k!=0)
if(node[k].marked=true)
{
dn[nodeno][index].par[k]=1;
for(int j=1;j<=n;j++)
{
dn[nodeno][index].par[j]=(dn[k][index].par[j]==1)?1:0;
}
}
}
}
}
public void call2a()
{
for(int i=1;i<=n;i++)
a2(node[i].node_no);
}
/* 2 A over*/
/* 2B starts */
public void call2b()
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<node[i].defvar.length;j++)
{
int index = varat(node[i].defvar[j]);            //index of def var in varnam list
dn[i][index].par[i]=1;                        //dynamic slice updated
rec_def[index]=i;
node[rec_def[index]].marked=false;
}
node[i].marked=true;
}
}

/* 2 C and 2 B over */

/* rest start*/
public void other()
{
for(int i=1;i<n+1;i++)
{
if(node[i].node_type.equals("pointcut"))
{
node[i].marked=true;
for(int j=0;j<node[i].actIn.length;j++)
node[node[i].actIn[j]].marked=true;
for(int j=0;j<node[i].actOut.length;j++)
node[node[i].actOut[j]].marked=true;
if(node[i].advice>0)                   //advice vertex is marked along with the formal in formal out
{
}
}
if(node[i].node_type.equals("sleep"))
{
node[i].marked=true;
}
}
}

public void call3a()
{
System.out.println(" enter the var name and the  node no");
int sw,sq;
String arg;
Scanner scan=new Scanner(System.in);
arg=scan.next();
sw=scan.nextInt();
sq=varat(arg);                          //index no of arg
for(int i=0;i<n;i++)
{
if(dn[sw][sq].par[i]==1)
System.out.print(dn[sw][sq].par[i]+1);
}
}

public static void main(String arg[]) throws Exception
{
//Input input=new Input();

Algo alg=new Algo();
alg.init();
System.out.println("\n\n\n\n\\n\n\n");
alg.call2a();
alg.call2b();
alg.other();
while(true)
{
alg.call3a();
System.out.println(" want to exit then enter 0");
Scanner scan=new Scanner(System.in);
int i=scan.nextInt();
if(i==0)break;
}
}/*end of main*/

}
```

Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.... node[]; StringTokenizer str,str1; Input() throws Exception { FileReader df=new FileReader("Input.txt"); Scanner fr=new Scanner(df); str=new StringTokenizer
Java stringtokenizer
Java stringtokenizer  What is difference between string and stringtokenizer
Query on StringTokenizer
Query on StringTokenizer   Sir,I kept my some data in backend using ms-access. for Example my data is like this vijayawada is good city.india is my country.i am raja. when i retrieve this data from backend and keep
program using StringTokenizer
program using StringTokenizer  I want to know about StringTokenizer,so can you please explain it with an example
StringTokenizer not returning proper result
StringTokenizer not returning proper result  I have this code... System.out.print("Enter the stack integers side by side with a space in between: "); StringTokenizer st=new StringTokenizer(br.readLine()); int a[]=new int[9000
arraylist problems?
arraylist problems?   myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList. After you have put all of the names into the ArrayList search through
Can iadd StringTokenizer into JLabel componenet
Can iadd StringTokenizer into JLabel componenet  l24="india.cricket.java.dotnet.oracle" String mn=l24; StringTokenizer mn1=new StringTokenizer(l24...(3,280,1580,600); nowon.setBackground(Color.cyan); sir i want to add StringTokenizer
Problems With Struts - Development process
Problems With Struts   Respected Sir , While Deploying Struts Application in Tomcat 5.0 ,using Forward Action.This can... resolve this problems. Thanks & Regards Akhtar
how to use stringtokenizer on table? and display in table format.
display result in row format  how to use stringtokenizer on table? and display in table format
problems regrading .properties files  According to my struts application my i ve to register particular data into the DB..It will succefully registerd according to my validation condition which m placed in the validate mathod
how to use stringtokenizer on table? and display in table format.
how to use stringtokenizer on table? and display in table format.  table is retrieved from mysql database and each row contains data like(java,c,c++,.net
Breaking a string into words without using StringTokenizer
Breaking a string into words without using StringTokenizer  how can we Break a string into words without using StringTokenizer ??   The given code convert the string into words. import java.util.*; class StringExample
Problems connecting to a database. Java/SQLite
Problems connecting to a database. Java/SQLite  `print("try { con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite"); } catch... on an SQL database but i am having problems connecting to it, I think the problem
Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get the values from the table( database), if any one of the column of the table value is 0. Then one alert should b printed in application using Java. If(att.getdata1()==0
problems in parsing the xml with the special characters
problems in parsing the xml with the special characters  Hi, I have a problem, in while parsing the xml with special characters apstrophe('). I am getting the exception Caused by: javax.xml.transform.TransformerException
start debugging problems related to the JDBC API
start debugging problems related to the JDBC API  How do I start debugging problems related to the JDBC API
nsstring get value - algebra multiplication problems
nsstring get value - algebra multiplication problems  NSString Algebra multiplication problems How can i get value of X using algebra multiplication problems in nsstring? if i have two values.. 3 + 8 + X = ? Thanks
Ask Programming Questions and Discuss your Problems       Dear Users, Analyzing your plenty of problems... all sorts of Java related problems round the clock. Believe it. Roseindia has
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby... { StringTokenizer st = new StringTokenizer( line, "; " ); while
Struts 1.2.9 (NB6.1) ? Problems with depend <html:select> and AJAX - Struts
Struts 1.2.9 (NB6.1) ? Problems with depend and AJAX  Hi I have 2 and one is depend to the other The 1st select I fill it of the DB with the help of the jstl :) but the 2nd will fill of the DB too but taking the 1st
Java StringTokenizer
Java StringTokenizer In this tutorial we will discuss about String Tokenizer... string into token,  first create a object of the StringTokenizer class, pass the string and the delimited string you want. StringTokenizer str = new
Software Design
Software Design       The process of solving problems and planning for a software solution is known as software design. In this process, first the purpose
Java Error
that describes the serious problems that a reasonable application should not try to catch
Categorizing Design Patterns
;  Patterns focus on different types of problems. Related... problems that application architecture should solve. These patterns are based... the problems.      Classification of JEE Design Patterns : 1
Introduction to Design Pattern
used to solve common object-oriented design issues (problems). When you design... should know at least some popular solutions to the coding problems. These solutions
Design Pattern
issues (problems). When you design a problem, you should know some common
, the integrated programming problems are also increasing. There are countless numbers... to share and sort out your problems. We have a strong network of software
Ask EJB Questions online       Whether are you a nascent programmer or proficient Enterprise JavaBeans developer, you might have faced several critical problems
Stay Safe Through a Home Security Mobile Application
security system will protect a home from invaders and other dangerous problems... any problems. A home security mobile application is one that can involve
JS-Sorcerer: JavaScript Development Tool
JS-Sorcerer: JavaScript Development Tool       JavaScript Reporter finds problems... productivity by quickly locating and reporting problems in JavaScript code
Lint4j Eclipse Plugin
Lint4j Eclipse Plugin         Eclipse is the perfect environment for using Lint4j. Problems can be reported as soon as the source is saved, and the Eclipse problem
Iteration
a set of values to solve real-world problems.  The for Statement
Wi-Fi Security for Public Networks
Wi-Fi Security for Public Networks       Introduction Wi-Fi hotspots present a unique set of security problems, quite different from the security issues involved in home and office
Protocols
-in solves these problems. With the Protocols plug-in, grouping is manifested both
JavaScript Reporter(tm) JavaScript Tool
JavaScript Reporter(tm) JavaScript Tool       JavaScript Reporter quickly locates and reports problems in JavaScript code. It detects and reports errors that could
VoIP Management Tools
that the tools provide. Such problems don't have simple answers. But vendors... can look deep into a user's network and pinpoint exactly where problems come
QuickREx
(or working late-night shifts to fix problems in production :-( ). QuickREx
Open Source c++
Open Source c++ Open Source C++ During our professional experience we have had many problems in finding drivers for industrial control cards... that many industrial control system developers have the same problems
Programming in Java for beginners
Programming in Java can be difficult sometimes especially for beginners in Java. In order to overcome such problems, we at RoseIndia provide a complete Java guide that has innumerous Java programs, examples, tutorials and videos
PHP Variables Dump
PHP Variables Dump There are some moments in our application when we face some problems or we work on someone else project the first thing we do is to check the detail of the contents or application either it is an array or object
PMD For Eclipse
PMD For Eclipse         PMD scans Java source code and looks for potential problems like: Possible bugs - empty try/catch/finally/switch statements Dead
Eclipse Metrics
during build cycles and warns you, via the Problems view, of 'range violations... will be added to the Problems View and the code will also be marked up. Exporting
Apache Struts 2.3.15.2 launched to fix vulnerable Feature
version of Apache Struts development framework to overcome two major problems... Struts 2.3.15.2 also fixes one more problems related to "action:" prefix
GPS Patient Tracking System
of any mishap that can create further problems for the hospitals. The hospital... these problems, the caretakers of the patients or the kin or the hospitals can use