Stupid Java Questions

Heretic_Cata

We're gonna live forever
Joined
Dec 27, 2005
Messages
9,587
Location
Romania
I don't need to learn java now because this is not for the java programing course.
There's the C++ programming course, the Java programming course, and THIS crappy course in which you have to learn programs like they are poems OR be the one of the 2 people out of 70 who understand the problems.

Anyway, i would like these "lines" explained in ****** language (that means i have to know what they do, not how it is done)

1.
StreamTokenizer st=new StreamTokenizer(new BufferedReader(new FileReader("fractii.in")));

From what i figure, this thing creates a file "fractii.in" ???

2.
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("fractii.out")));

This writes something (?) in a file "fractii.out".

3.
st.nextToken();n=(int)st.nval;
st.nextToken();m=(int)st.nval;

No idea

Note: n & m were defined earlier.

4.
What's the java equivalent of the C++ :
printf("bla");
scanf("%n", &x); <--- hope i remembered this one right :D



That's about it for now ...
Thanx in advance. :)
 
1. Sets up a stream which will allow you to read data from the file "fractii.in"

2. Sets up a stream which will allow you to write data to the file "fractii.out"

3. Read the next token from the file "fractii.in" store it in variable n. Read the next one after that and store it in variable m.
 
1. Creates a StreamTokenizer object. A tokenizer is something to use to split a text into individual components (such as words). It uses a "token" by which to separate the texts. Since no token is mentioned here, the tokenizer will use spaces.
For instance, this sentence will be split like this:
{"For", "instance,", "this", "sentence", "will", "be", "split", "like", "this:"}
The st.NextToken extracts the "next token" from the designated stream.

PrintWriter


What's the java equivalent of the C++ :
printf("bla");
scanf("%n", &x); <--- hope i remembered this one right
the first one is: System.out.print("bla");
the second one is a little more complicated. Java is not usually used to retreive data from the user input (that's why you use a GUI form).
This is my take on it:
Code:
/*
 * InputStringReader.java
 */

import java.io.*;

/**
 * @author adi
 *
 *  Used to read a string from the standard input.
 */
public class InputStringReader {
    public static String readString () {
      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String s = null;
      
      try {
         s = br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read from stream!");
         ioe.printStackTrace();
         System.exit(1);
      }
      return s;
   }
}
Use the static method in that class to read a string from the user input. Java has good functions to convert from string to the data type of your choice.

If you need more information about specific classes, all you have to do is search google: "MyClassName class java"

You should really look for some tutorials, there are plenty out there.
 
Thanx guys, all clear now. :worship::thanx: Except for the scanf part which is waaaaaaaay out of my lead. But that question was more of a curiosity than a necesity.

More stupid java questions are coming.
I don't actually want to start learning java thorughly ... like i said in the OP ; it's kinda complicated, the course doesn't even teach java.

@Aphex_Twin: Sal :wavey:
Nu prea te-am vazut de mult pe forum. Dupa nr de posturi (:eek:) vad ca erai mult mai activ mai demult. :)

But after a quick search i see you post mostly in OT ... maybe that's why i never saw you around.
 
warpus said:
Dupa in polish means 'ass'.

Are you guys talking about asses?
:rotfl:
Not exactly. :lol:
"Dupa" usually means "after", in this case it means "according to" or something close to that.
 
Back
Top Bottom