B
bulletant01
I had a problem with my code... can anybody help me with this..? i
cannot input more than 10 no.s. i think it something to do with the
length of my String.. but i cannot figure out wheres the problem. by
the way heres my code>>>>>>>>
/
*********************************************************************************************************/
import javax.swing.*;
public class Automata {
public static void main(String[] args) {
String input = "";
String [] numLet = new String [100];
int [] oddzero = new int[100];
String ans1 = "";
String ans2="";
String choice ="";
do
{
choice = JOptionPane.showInputDialog("\t\t\t"+ "ress One(1)
to accept a string of Odd Number of Zero(0) and Even Number of One
(1):"+"\n"+
"\t\t\t"+ "ress One(2) to accept a string of Odd Number of
One(1) and Even Number of Zero(0):"+"\n"+
"\t\t\t"+"ress three(3) to exit:"+"\n"+
"\t\t\t"+"ENTER YOUR CHOICE");
switch(Integer.parseInt(choice))
{
case 1:
input = JOptionPane.showInputDialog("ENTER A NUMBER(S) (ONE(1)
AND ZERO(0))");
for(int a = 0; a<input.length();a++)
{
numLet[a] = String.valueOf(input.charAt(a));
}
for(int b = 0; b<input.length();b++)
{
oddzero[b+b] = 1;
oddzero[b+b+1]= 0;
}
for(int c = 0; c<input.length();c++)
{
ans1 = ans1+String.valueOf(oddzero[c]);
ans2 = ans2+String.valueOf(numLet[c]);
}
if (Integer.parseInt(ans1) == Integer.parseInt(ans2))
{
JOptionPane.showMessageDialog(null,"ACCEPTED!!");
}
else
{
JOptionPane.showMessageDialog(null,"NOT ACCEPTED!!");
}
ans1 = "";
ans2 = "";
break;
case 2:
input = JOptionPane.showInputDialog("ENTER A NUMBER(S) (ONE(1)
AND ZERO(0))");
for(int a = 0; a<input.length();a++)
{
numLet[a] = String.valueOf(input.charAt(a));
}
for(int b = 0; b<input.length();b++)
{
oddzero[b+b] = 0;
oddzero[b+b+1]= 1;
}
for(int c = 0; c<input.length();c++)
{
ans1 = ans1+String.valueOf(oddzero[c]);
ans2 = ans2+String.valueOf(numLet[c]);
}
if (Integer.parseInt(ans1) == Integer.parseInt(ans2))
{
JOptionPane.showMessageDialog(null,"ACCEPTED!!");
}
else
{
JOptionPane.showMessageDialog(null,"NOT ACCEPTED!!");
}
ans1 = "";
ans2 = "";
break;
case 3:
JOptionPane.showMessageDialog(null,"EXIT!!");
break;
default:
JOptionPane.showMessageDialog(null,"WRONG CHOICE!!");
break;
}
}
while(Integer.parseInt(choice)!=3);
}
}
cannot input more than 10 no.s. i think it something to do with the
length of my String.. but i cannot figure out wheres the problem. by
the way heres my code>>>>>>>>
/
*********************************************************************************************************/
import javax.swing.*;
public class Automata {
public static void main(String[] args) {
String input = "";
String [] numLet = new String [100];
int [] oddzero = new int[100];
String ans1 = "";
String ans2="";
String choice ="";
do
{
choice = JOptionPane.showInputDialog("\t\t\t"+ "ress One(1)
to accept a string of Odd Number of Zero(0) and Even Number of One
(1):"+"\n"+
"\t\t\t"+ "ress One(2) to accept a string of Odd Number of
One(1) and Even Number of Zero(0):"+"\n"+
"\t\t\t"+"ress three(3) to exit:"+"\n"+
"\t\t\t"+"ENTER YOUR CHOICE");
switch(Integer.parseInt(choice))
{
case 1:
input = JOptionPane.showInputDialog("ENTER A NUMBER(S) (ONE(1)
AND ZERO(0))");
for(int a = 0; a<input.length();a++)
{
numLet[a] = String.valueOf(input.charAt(a));
}
for(int b = 0; b<input.length();b++)
{
oddzero[b+b] = 1;
oddzero[b+b+1]= 0;
}
for(int c = 0; c<input.length();c++)
{
ans1 = ans1+String.valueOf(oddzero[c]);
ans2 = ans2+String.valueOf(numLet[c]);
}
if (Integer.parseInt(ans1) == Integer.parseInt(ans2))
{
JOptionPane.showMessageDialog(null,"ACCEPTED!!");
}
else
{
JOptionPane.showMessageDialog(null,"NOT ACCEPTED!!");
}
ans1 = "";
ans2 = "";
break;
case 2:
input = JOptionPane.showInputDialog("ENTER A NUMBER(S) (ONE(1)
AND ZERO(0))");
for(int a = 0; a<input.length();a++)
{
numLet[a] = String.valueOf(input.charAt(a));
}
for(int b = 0; b<input.length();b++)
{
oddzero[b+b] = 0;
oddzero[b+b+1]= 1;
}
for(int c = 0; c<input.length();c++)
{
ans1 = ans1+String.valueOf(oddzero[c]);
ans2 = ans2+String.valueOf(numLet[c]);
}
if (Integer.parseInt(ans1) == Integer.parseInt(ans2))
{
JOptionPane.showMessageDialog(null,"ACCEPTED!!");
}
else
{
JOptionPane.showMessageDialog(null,"NOT ACCEPTED!!");
}
ans1 = "";
ans2 = "";
break;
case 3:
JOptionPane.showMessageDialog(null,"EXIT!!");
break;
default:
JOptionPane.showMessageDialog(null,"WRONG CHOICE!!");
break;
}
}
while(Integer.parseInt(choice)!=3);
}
}