View Full Version : Stupid Java Questions


Heretic_Cata
Sep 08, 2006, 04:22 AM
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 retard 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. :)

warpus
Sep 08, 2006, 10:32 AM
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.

Aphex_Twin
Sep 08, 2006, 03:04 PM
1. Creates a StreamTokenizer (http://java.sun.com/j2se/1.4.2/docs/api/java/io/StreamTokenizer.html) 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 (http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintWriter.html)


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:
/*
* 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.

Heretic_Cata
Sep 08, 2006, 04:17 PM
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.

Aphex_Twin
Sep 08, 2006, 06:19 PM
@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. :)Mai putin cu forumul in ultima vreme. Am mai stat pe Essembly (http://essembly.com), Skype (www.skype.com), alte forumuri (http://www.graveyardofthegods.com/forum/index.php), site-uri (http://radicallibertarians.blogspot.com/) sau blogul meu (http://anarchy.wordpress.com).

Cat despre asta:
More stupid java questions are coming.
Incearca niste tutoriale (http://www.google.ro/search?q=java+tutorials&start=0&ie=utf-8&oe=utf-8&client=firefox&rls=org.mozilla:en-US:unofficial), nu doare ;)

warpus
Sep 09, 2006, 11:16 PM
Dupa nr de posturi

Dupa in polish means 'ass'.

Are you guys talking about asses?

Heretic_Cata
Sep 10, 2006, 03:26 AM
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.