By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Anyone for a small Java challenge?

P: n/a

Greetings to all -

Someone suggested that Java might be the answer for a little
conversion program I need. It's pretty simple, really. Just take a
column of numbers:

139
259
433
637
799
1053
1185

and multiply them all by the same number, and spit out a new column.
I'm multipilying by "29.97" in this case. I'm trying to convert a
column of video times to frames.

That would end up looking like:

4165.83
7762.23
12977.01
(etc)

although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Can anyone help me out?

Thanks much,
Dr. Merc
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
> Someone suggested that Java might be the answer for a little
conversion program I need. It's pretty simple, really. Just take a
column of numbers:

139
259
433
637
799
1053
1185

and multiply them all by the same number, and spit out a new column.
I'm multipilying by "29.97" in this case. I'm trying to convert a
column of video times to frames.

That would end up looking like:

4165.83
7762.23
12977.01
(etc)

although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Sounds like a job for Excel...

how often do you plan to do this?
Where do you get the column of numbers, and how
do you use them? In what way would writing a
program be easier than using a calculator?
For starts, see below - this is about
as simple as it gets:
import java.io.*;
import java.lang.Math;
import java.lang.Double;

public class Convertor {
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );

public static void main(String[] args) {
double d;
System.out.println("Enter your list of values:");

while (true) {
d = Double.parseDouble(stdin.readLine());
System.out.println( Math.floor( d * 29.97) );
}
}
}
Jul 17 '05 #2

P: n/a
On Fri, 20 Feb 2004 01:41:43 -0500, "Hugh Bothwell" wrote:

<sniplet>
although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Sounds like a job for Excel...
Howdy, Hugh, thanks for the reply.

It works fine in Excel, but I need this as part of a video procedure
on my Web site, so it should be something freeware.
how often do you plan to do this?
Where do you get the column of numbers, and how
do you use them? In what way would writing a
program be easier than using a calculator?
It's a matter of retaining the chapter points in an SVCD when
converting to another format. The chapter points can be extracted as
times, but the conversion program wants them as frames. Ergo, I need
to be able to multiply a column of numbers by either 23.976 or 29.97
(frame rate of the movie depending) to convert the times to frames. A
calculator would work, certainly, but it'd be a tad laborious for 20
or so entries.
For starts, see below - this is about
as simple as it gets:
Note the small font mismatch below:
public static void main(String[] args) {


If you could fix that, and let me know how to use the script, it'd be
appreciated. I honestly don't know anything about Javascripts except
that occasionally I use a chunk of them in my Web pages, like to
pre-load dynamic icons. I don't have any idea how to run an
independent script like this one.

Thanks for the help,
Doc

--

For all of your DVD/SVCD/DIVX/OGM needs: www.svcd.cc
New to DVD recording? www.svcd.cc/dvdrinfo.htm

VCD FAQ: http://abvcd.home.comcast.net/FAQ/abvcdfaq5.01.htm
SVCD Charter: www.svcd.cc/charter.htm

Jul 17 '05 #3

P: n/a
nos
awk '{print int($1 * 29.97);}' < numbers.txt
"Dr. Mercury" <wh@ts.up.doc> wrote in message
news:67********************************@4ax.com...

Greetings to all -

Someone suggested that Java might be the answer for a little
conversion program I need. It's pretty simple, really. Just take a
column of numbers:

139
259
433
637
799
1053
1185

and multiply them all by the same number, and spit out a new column.
I'm multipilying by "29.97" in this case. I'm trying to convert a
column of video times to frames.

That would end up looking like:

4165.83
7762.23
12977.01
(etc)

although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Can anyone help me out?

Thanks much,
Dr. Merc

Jul 17 '05 #4

P: n/a
"Dr. Mercury" <wh@ts.up.doc> wrote in message
news:ap********************************@4ax.com...
On Fri, 20 Feb 2004 01:41:43 -0500, "Hugh Bothwell" wrote:

<sniplet>
although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Sounds like a job for Excel...


Howdy, Hugh, thanks for the reply.

It works fine in Excel, but I need this as part of a video procedure
on my Web site, so it should be something freeware.
how often do you plan to do this?
Where do you get the column of numbers, and how
do you use them? In what way would writing a
program be easier than using a calculator?


It's a matter of retaining the chapter points in an SVCD when
converting to another format. The chapter points can be extracted as
times, but the conversion program wants them as frames. Ergo, I need
to be able to multiply a column of numbers by either 23.976 or 29.97
(frame rate of the movie depending) to convert the times to frames. A
calculator would work, certainly, but it'd be a tad laborious for 20
or so entries.
For starts, see below - this is about
as simple as it gets:


Note the small font mismatch below:
public static void main(String[] args) {


If you could fix that, and let me know how to use the script, it'd be
appreciated. I honestly don't know anything about Javascripts except
that occasionally I use a chunk of them in my Web pages, like to
pre-load dynamic icons. I don't have any idea how to run an
independent script like this one.

Thanks for the help,
Doc

That's Java. It's what you asked for. It's not javascript or "a script" at
all. It's a Java program. See the Java Tutorial:
http://java.sun.com/docs/books/tutorial/

Specifically, pay attention to "Your First Cup of Java".
Jul 17 '05 #5

P: n/a
"Hugh Bothwell" <hu***********@hotmail.com> wrote in message news:<qV*******************@nntp-post.primus.ca>...
Someone suggested that Java might be the answer for a little
conversion program I need. It's pretty simple, really. Just take a
column of numbers:

139
259
433
637
799
1053
1185

and multiply them all by the same number, and spit out a new column.
I'm multipilying by "29.97" in this case. I'm trying to convert a
column of video times to frames.

That would end up looking like:

4165.83
7762.23
12977.01
(etc)

although I'd like the decimal dropped, so it ends up looking like:

4165
7762
12977
(etc)

Sounds like a job for Excel...

how often do you plan to do this?
Where do you get the column of numbers, and how
do you use them? In what way would writing a
program be easier than using a calculator?
For starts, see below - this is about
as simple as it gets:
import java.io.*;
import java.lang.Math;
import java.lang.Double;

public class Convertor {
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );

public static void main(String[] args) {
double d;
System.out.println("Enter your list of values:");

while (true) {
d = Double.parseDouble(stdin.readLine());
System.out.println( Math.floor( d * 29.97) );
}
}
}


Are you going to have a text file to input these numbers, and then
output them in another text file?

I could write that, just let me know.

Aaron
Jul 17 '05 #6

P: n/a
On 20 Feb 2004 18:01:57 -0800, aa*********@sendit.nodak.edu (Aaron)
wrote:

<sniplet>
Are you going to have a text file to input these numbers, and then
output them in another text file?

I could write that, just let me know.


Yep, that's the idea. "chapters.txt" would be converted to
"chapters2.txt". Any help with this, and how to run it, would
certainly be appreciated.

Doc

Jul 17 '05 #7

P: n/a
SPC
something like this:

Input numberes in a File1
-Open File1
- Input numbers.
-Close File1
And
-Open File2
- Open File1
- Copy File1 into File2
- Close File1
-Close File2

Sorry, if I misunderstand.
S.P.C

Code:
package Chapters;

import java.io.*;

public class Chapter {

private static String sLine;
private static PrintWriter FileCopy;
private static BufferedReader stdin = new BufferedReader( new
InputStreamReader( System.in ) );

public static void main (String[] args) throws IOException {

Convert() ;
File();

}//fin Main

private static void Convert() throws IOException {

int n=3; //Take 3 inputs
double d;
System.out.print("Enter your list of values:");

FileCopy = new PrintWriter(new FileOutputStream("Test.txt"));

for (int i= 0; i < n ; i++ ){
d = Double.parseDouble(stdin.readLine());
d = (short)(d * 29.97); // 4165.83 --> 4165.0

System.out.println((int)d); //4165.0 --> 4165
FileCopy.println((int)d);

}
FileCopy.close(); //Close Write File : Copy.txt

}//Fin Convert()

private static void File() throws IOException {

BufferedReader FileRead;

FileCopy = new PrintWriter(new FileOutputStream("Copy.txt"));
FileRead = new BufferedReader(new FileReader("Test.txt"));

//Read file "Text.txt" and Copy it in "Copy.tx"t
while ( (sLine = FileRead.readLine()) != null) {
FileCopy.println(sLine);

} //Fin while

FileRead.close(); //Close Read File : Test.txt
FileCopy.close(); //Close Write File : Copy.txt

} // Fin File()

}//Fin Class



"Dr. Mercury" <wh@ts.up.doc> a écrit dans le message de
news:lg********************************@4ax.com...
On 20 Feb 2004 18:01:57 -0800, aa*********@sendit.nodak.edu (Aaron)
wrote:

<sniplet>
Are you going to have a text file to input these numbers, and then
output them in another text file?

I could write that, just let me know.


Yep, that's the idea. "chapters.txt" would be converted to
"chapters2.txt". Any help with this, and how to run it, would
certainly be appreciated.

Doc

Jul 17 '05 #8

P: n/a
On Sun, 22 Feb 2004 19:46:54 -0500, "SPC" <he**@sayimpossible.ca.tc>
wrote:
something like this: Input numbers in a File1


<snip>

Thanks very much for the interesting script. Can you give me a brief
rundown on how to use it? I have the general idea, but I could use
some specifics.

Thanks much,
Doc

Jul 17 '05 #9

P: n/a
SPC
Are you talking about" Input numbers" by ?? Math.random() ?? and multi
with 29.97 .
And you want the result in Integer (decimal dropped).
You see the example below,

SPC.
//*************
Ex:
int d ;

d = (int)( Math.random()*29.97 ); // (int) : (decimal dropped).
//this give you ONE number by Random, multi it with 29.97 and convert it in
Integer.

//**********
PS: Sorry, English is not my 1st lan.
"Dr. Mercury" <wh@ts.up.doc> a écrit dans le message de
news:nl********************************@4ax.com...
On Sun, 22 Feb 2004 19:46:54 -0500, "SPC" <he**@sayimpossible.ca.tc>
wrote:
something like this:

Input numbers in a File1


<snip>

Thanks very much for the interesting script. Can you give me a brief
rundown on how to use it? I have the general idea, but I could use
some specifics.

Thanks much,
Doc

Jul 17 '05 #10

P: n/a
On Mon, 23 Feb 2004 20:21:13 -0500, "SPC" <he**@sayimpossible.ca.tc>
wrote:
Are you talking about" Input numbers" by ?? Math.random() ?? and multi
with 29.97 .
And you want the result in Integer (decimal dropped).


Actually, the decimal doesn't have to be dropped. The program the
numbers go into is very 'sensitive' and I didn't want to confuse it
with decimals places, but it seems to just ignore them. So all I want
is something to multiply a list of numbers and produce a new list. If
you could write up a script and tell me how to use it, it would
certainly be appreciated.

Thanks,
Doc

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.