C++ IO Streams in Java?

I'm a long time programmer in C++, and have gotten use to it's use of IO streams. My question is, what's the simplest way to recreate the following code in Java?

#include <iostream>

void main()
{
 char string1[100], string2[100]
 cin >> string1 >> string2;
 cout << string1 << string2 << endl;
}

Thanks...
dleslieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dleslieAuthor Commented:
Incase you didn't read into my question, I'm looking for FULL source :)
0
NamCommented:
Hello dleslie,

Try to review the following code:


import java.io.*;

public class IODemo {
   public static void main(String [] args) {
        String string1=null, string2=null;
        try {
             DataInputStream dis = new DataInputStream(System.in);
             string1 = dis.readLine();
             string2 = dis.readLine();
       } catch (IOException ioe) {
             System.out.println("IOException: "+ ioe.toString());
             System.exit(1);
       }
       System.out.println(string1 + string2);
  }
}


Good luck,
--
0
shaveriCommented:
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

dleslieAuthor Commented:
Close, but not exactly what I'm looking for.

The way you designed requires two carriage returns, the c++ code I showed required one. Eg,
User enters:
Hi There

Hi is stored in string1
There is stored in string2

Output:
Hi There


BUT, your java code would require the user to enter:
Hi
There

You see what I mean? This is a problem I've been trying to get around for a while...

Thanks,
-Dan
0
dleslieAuthor Commented:
BTW, I was replying to the comment, that wasn't quite the answer I was looking for :)

-Dan
0
captainkirkCommented:
You could input into one string and use the StringTokenizer class to separate the tokens into different string variables...
0
jjdunneCommented:
import java.io.*;
import java.util.*;

public class IODemo {
   public static void main(String [] args) {
      String inputString=null, string1=null, string2=null;
         try {
            DataInputStream dis = new DataInputStream(System.in);
            inputString = dis.readLine();
         } catch (IOException ioe) {
             System.out.println("IOException: "+ ioe.toString());
             System.exit(1);
         }
      StringTokenizer stk = new StringTokenizer(inputString);
      string1 = stk.nextToken();
      string2 = stk.nextToken();
      System.out.println(string1 + " : " + string2);
   }
}


I'll submit this as a comment, since I do not deserve all the points....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
captainkirkCommented:
I believe that's what I had in mind ... except you may have to specify what char(s) you want as delimiters...
0
dleslieAuthor Commented:
Hmm, I'll try that, but right now, I've got Corel Linux to install, so, I'll post again in a few (hours)?

Thanks,
-Dan
0
dleslieAuthor Commented:
Works perfectly! So, who's going to propose it as an answer? I'm inclined to give it to jjdunne (for actually proposing code)...

-Dan
0
dleslieAuthor Commented:
Exactly!
0
captainkirkCommented:
go for it, jjdunne...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.