- #1
major_maths
- 30
- 0
I'm trying to make a program that prompts a user to enter a binary number and then converts the string into integers by using Integer.parseInt. Right now though, I'm having trouble with tokenizing the string. My code works when I use the predefined variable temp but not when I enter the same thing into the String variable inputLine.
Code:
import java.util.*;
public class testBitConverter
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a string.");
String inputLine = keyboard.next();
String temp = "1 1 0 0 0 1 1 1";
StringTokenizer tester = new StringTokenizer(inputLine);
String first = tester.nextToken();
String second = tester.nextToken();
String third = tester.nextToken();
String fourth = tester.nextToken();
String fifth = tester.nextToken();
String sixth = tester.nextToken();
String seventh = tester.nextToken();
String eighth = tester.nextToken();
System.out.println("This is the output: ");
System.out.println("first token: "+first);
System.out.println("second token: "+second);
System.out.println("third token: "+third);
System.out.println("fourth token: "+fourth);
System.out.println("fifth token: "+fifth);
System.out.println("sixth token: "+sixth);
System.out.println("seventh token: "+seventh);
System.out.println("eighth token: "+eighth);
}
}