• We've upgraded our forums. Please post any issues/requests in this thread.

Help a beginner with Java

Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#1
<Original question answered>

Edit: I'll post more questions as I'm learning.
 
Last edited by a moderator:
Joined
Jul 26, 2010
Messages
1,655 (0.61/day)
Likes
729
Location
Philly
System Name Primary Rig
Processor Phenom II X4 B50 @ 3.7GHz
Motherboard Biostar TA790GX 128M
Cooling Sunbeam CR-CCTF 120mm , 6x120mm, MOS-C1
Memory 2x2GB Kingston HyperX 1066 @ 800 4-4-4-12
Video Card(s) Sapphire HD 5830 800/1000 @ 885/1225
Storage 320GB, 400GB, 500GB, 1.5TB
Display(s) Hannspree HF259
Case CM 690
Power Supply OCZ 850W
Benchmark Scores 3Dmark06: 18545/5219 CPU Mark 7.0: 3911.2 Cinebench R10: 11826/3359 x264 HD 2.0: 75.6/23.9
#2
If you already have it working for classes why doesn't it work for javac? Maybe you just need to use something like "javac .\myfile.java"?

All you should need to do is add the Java directory to the "path" system variable.
 

Easy Rhino

Linux Advocate
Joined
Nov 13, 2006
Messages
14,405 (3.56/day)
Likes
4,256
System Name VHOST01 | Desktop
Processor i7 980x | i5 7500 Kaby Lake
Motherboard Gigabyte x58 Extreme | AsRock MicroATX Z170M Exteme4
Cooling Prolimatech Megahelams | Stock
Memory 6x4 GB @ 1333 | 2x 8G Gskill Aegis DDR4 2400
Video Card(s) Nvidia GT 210 | Nvidia GTX 970 FTW+
Storage 4x2 TB Enterprise RAID5 |Corsair mForce nvme 250G
Display(s) N/A | Dell 27" 1440p 8bit GSYNC
Case Lian Li ATX Mid Tower | Corsair Carbide 400C
Audio Device(s) NA | On Board
Power Supply SeaSonic 500W Gold | Seasonic SSR-650GD Flagship Prime Series 650W Gold
Mouse N/A | Logitech G900 Chaos Spectrum
Keyboard N/A | Posiden Z RGB Cherry MX Brown
Software Centos 7 | Windows 10
#3
set the path for it i believe.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#4
How do you set the path for it? I've been reading around and am completely confused.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#5
Another question.

In the following code:
public class Addition {
public Addition( ) {
int x, y = 1, z = 2;

x = y + z;
System.out.println("+ operator resulted in "+x);
}

public static void main(String args[]){
new Addition();
}
}
is

public Addition( ) {
the method header

int x, y = 1, z = 2;

x = y + z;
System.out.println("+ operator resulted in "+x);
}
the method body and
new Addition();
the method call?
 
Joined
Jul 26, 2010
Messages
1,655 (0.61/day)
Likes
729
Location
Philly
System Name Primary Rig
Processor Phenom II X4 B50 @ 3.7GHz
Motherboard Biostar TA790GX 128M
Cooling Sunbeam CR-CCTF 120mm , 6x120mm, MOS-C1
Memory 2x2GB Kingston HyperX 1066 @ 800 4-4-4-12
Video Card(s) Sapphire HD 5830 800/1000 @ 885/1225
Storage 320GB, 400GB, 500GB, 1.5TB
Display(s) Hannspree HF259
Case CM 690
Power Supply OCZ 850W
Benchmark Scores 3Dmark06: 18545/5219 CPU Mark 7.0: 3911.2 Cinebench R10: 11826/3359 x264 HD 2.0: 75.6/23.9
#6
How do you set the path for it? I've been reading around and am completely confused.
Easiest way to do it is in System Properties (in Windows 7 you can use Start->Run->systempropertiesadvanced.exe).


Then select Environment Variables and you'll see this window.


Then click "Path" in the lower box and hit "Edit" and you'll get here:


Then just add a semicolon and the path to your Java directory (with javac).
Another question.
I'm pretty sure that's correct, though my terminology is a bit rusty.
 
Last edited:
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#7
I ignored path and thought I had to add SOURCEPATH :banghead:

Edit: I've already done that what I meant was how do I set it (cmd) to know where my .java files are, not javac.
 
Last edited:
Joined
Jul 26, 2010
Messages
1,655 (0.61/day)
Likes
729
Location
Philly
System Name Primary Rig
Processor Phenom II X4 B50 @ 3.7GHz
Motherboard Biostar TA790GX 128M
Cooling Sunbeam CR-CCTF 120mm , 6x120mm, MOS-C1
Memory 2x2GB Kingston HyperX 1066 @ 800 4-4-4-12
Video Card(s) Sapphire HD 5830 800/1000 @ 885/1225
Storage 320GB, 400GB, 500GB, 1.5TB
Display(s) Hannspree HF259
Case CM 690
Power Supply OCZ 850W
Benchmark Scores 3Dmark06: 18545/5219 CPU Mark 7.0: 3911.2 Cinebench R10: 11826/3359 x264 HD 2.0: 75.6/23.9
#8
Edit: I've already done that what I meant was how do I set it (cmd) to now where my where my .java files are, not javac.
Well it doesn't really work that way as far as I know, but it does work the other way.

You have to type in the directory of your .java files at one time or another. The idea is usually to cd into the directory with your .java files and then all you need to do is type "javac myfile.java". You could also make a batch file which would simplify the process even further.
 

Easy Rhino

Linux Advocate
Joined
Nov 13, 2006
Messages
14,405 (3.56/day)
Likes
4,256
System Name VHOST01 | Desktop
Processor i7 980x | i5 7500 Kaby Lake
Motherboard Gigabyte x58 Extreme | AsRock MicroATX Z170M Exteme4
Cooling Prolimatech Megahelams | Stock
Memory 6x4 GB @ 1333 | 2x 8G Gskill Aegis DDR4 2400
Video Card(s) Nvidia GT 210 | Nvidia GTX 970 FTW+
Storage 4x2 TB Enterprise RAID5 |Corsair mForce nvme 250G
Display(s) N/A | Dell 27" 1440p 8bit GSYNC
Case Lian Li ATX Mid Tower | Corsair Carbide 400C
Audio Device(s) NA | On Board
Power Supply SeaSonic 500W Gold | Seasonic SSR-650GD Flagship Prime Series 650W Gold
Mouse N/A | Logitech G900 Chaos Spectrum
Keyboard N/A | Posiden Z RGB Cherry MX Brown
Software Centos 7 | Windows 10
#9
first off, not to be a dick, but you gotta correct your grammar. i had to read your question 3 times before i figured out what you were asking. better grammar means more people willing to help.

a .java file is the source code. you run javac on the .java file to compile it into a class file which you then execute running the java <your java class file>.

so you have to either be in the directory of your compiled java program or include the entire working directory.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#10
I just changed the default start directory for a shortcut of cmd. That solves that problem.

first off, not to be a dick, but you gotta correct your grammar. i had to read your question 3 times before i figured out what you were asking. better grammar means more people willing to help.
I couldn't think of a better way to word it (otherwise I would've just googled it...)
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#11
I popped my programing cherry.
import java.util.Scanner;

public class test {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);

int a;
int b;
int c;

System.out.print("a = ");
a = input.nextInt();

System.out.print("b = ");
b = input.nextInt();

c = a + b;
System.out.print(c);
}
}

I'm going to practice with maths for now then do that archery thing Kreij mentioned in another thread.

PS. Is it bad to have to regularly look up syntax?
 
Joined
Nov 18, 2006
Messages
2,964 (0.73/day)
Likes
397
Location
your local vending machine
System Name HTPC||Lenovo IBM ThinkPad
Processor AMD Phenom II x4 965 stock 3.4GHz||Intel C2D T9300 @ 2.5GHz
Motherboard Zotac 890GX-ITX WiFi||Lenovo 8918CTO
Cooling Stock 3x 120's||Stock stuff
Memory 8GB (2x4GB) DDR3 6-6-6-15||3GB DDR2
Video Card(s) Asus 3870x2||nVidia Quadro NVS 140M
Storage 1TB Seagate Barracuda, 1x 2TB WD EARX ||Hitachi 160GB 7200RPM
Display(s) Samsung T260HD||
Case SilverStone Grandia GD05||
Audio Device(s) on-board||on-board
Power Supply Cooler Master 450W||6-cell
Software Windows 7 Pro x64||Windows 7 Pro x64/Linux Mint x64
#12
PS. Is it bad to have to regularly look up syntax?
Not at all for a beginner! :)
I still have to look up syntax for some things. The more you do it, the easier it will become and the less you will have to reference
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#13
No raz, with 1000s of APIs and a jillion methods that are available in some of the modern programming languages, and the fact that with language revisions they will add/obsolete calls, you will be using references constantly.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#14
I was looking for java keyword definitions and found them on Wikipedia. The definition of "void" has me confused.
Wikipedia defines void as, "The void keyword is used to declare that a method does not return any value.", if that's true how did the code I posted earlier return a value?:wtf:

EDIT: Also, can any of you folks remember how long it took you to start using correct case letters (upper/lowercase) in code? That seems to be the commonest error I make.
 
Last edited:
Joined
Aug 10, 2007
Messages
4,058 (1.07/day)
Likes
1,122
Location
Geneva, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
#15
That's because it didn't return anything, unlike this (poor) example:

Code:
public int getTheNumberTen() {
	return 10;
}
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#16
Then would I be correct in assuming returning a value means "returning a value to the code"?



Another question:
The following code makes cmd say "Your target is x" where x is a value.
System.out.println("Your target is " +x_target)
However I want cmd to say "Your target is x meters away" where x is a value. The code I'm using to make this happen is,
System.out.println("Your target is " +x_target " meters away")
, which doesn't work/compile. What do I have to do to make it work/compile?
 
Last edited:
Joined
Aug 10, 2007
Messages
4,058 (1.07/day)
Likes
1,122
Location
Geneva, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
#17
Seems like you're missing a "+" after the x_target variable. You need it to concatenate " meters away" with the beginning portion.


That's one way to describe it. It's going to return the result so you may do with it as you will.

Ex: Lets say you have a function that returns a value describing how close a user got to the the target based on the angle, meters away, and the bow pull. It's something that you want to print out, but also save in an array so that the user can see their last ten moves or something like that.

Code:
proximity = getProximity(angle, meters, power)
Now you can print out the variable proximity and store it.

Note: Much more familiar with PHP, sorry if my Java syntax is off.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#18
Is it better to have several small formulae,
u = Math.sqrt((2 * P * t_bow) / m);

t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

or one big formula,
x = Math.round(((Math.sqrt((2 * P * t_bow) / m) * Math.sin(Math.toRadians(theta))) / 4.9) * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;
?
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#19
So far I have this for the archery game,
import java.util.Scanner;

public class archery{
public static void main(String args[]){
Scanner input = new Scanner(System.in);

double x_target;
double P;
double theta;
double u;
double t;
double x;
double s_target;
double d_target;
double m = 1.0;
double t_bow = 1.0;

System.out.println("Let's shot some arrows!");

x_target = 1 + (Math.round(100 * Math.random() * 100)/100.0d);
System.out.println("Your target is " +x_target+ " meters away");
System.out.println();

System.out.println("How much power will you pull the bow with: ");
P = input.nextDouble();
System.out.println();

System.out.println("At what angle will you shoot your arrow: ");
theta = input.nextDouble();
System.out.println();

u = Math.sqrt((2 * P * t_bow) / m);

t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

s_target = x_target - x;

if (s_target < 0){
d_target = s_target * -1;
}
else{
d_target = s_target;
}

if (d_target > 1){
System.out.println("You were "+Math.round(d_target * 100) / 100.0d+" meters off");
}
else {
System.out.println("Well done you hit the target");
}
}
}

How do I make it return to the bit just after it's worked out "x_target" if "d_target" > 1?
Other than that it works, yay.

EDIT: I can advertise this game as using real Newtonian physics, lol.
 
Last edited:
Joined
Jul 26, 2010
Messages
1,655 (0.61/day)
Likes
729
Location
Philly
System Name Primary Rig
Processor Phenom II X4 B50 @ 3.7GHz
Motherboard Biostar TA790GX 128M
Cooling Sunbeam CR-CCTF 120mm , 6x120mm, MOS-C1
Memory 2x2GB Kingston HyperX 1066 @ 800 4-4-4-12
Video Card(s) Sapphire HD 5830 800/1000 @ 885/1225
Storage 320GB, 400GB, 500GB, 1.5TB
Display(s) Hannspree HF259
Case CM 690
Power Supply OCZ 850W
Benchmark Scores 3Dmark06: 18545/5219 CPU Mark 7.0: 3911.2 Cinebench R10: 11826/3359 x264 HD 2.0: 75.6/23.9
#20
Is this what you want?
Code:
 . . .

[B]double d_target=2;[/B]

 . . . 

x_target = 1 + (Math.round(100 * Math.random() * 100)/100.0d);
[B]while (d_target > 1) {[/B]
     System.out.println("Your target is " +x_target+ " meters away");
     System.out.println();

     System.out.println("How much power will you pull the bow with: ");
     P = input.nextDouble();
     System.out.println();

     System.out.println("At what angle will you shoot your arrow: ");
     theta = input.nextDouble();
     System.out.println();
     
     u = Math.sqrt((2 * P * t_bow) / m);

     t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

     x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

     s_target = x_target - x;

     if (s_target < 0){
          d_target = s_target * -1;
     }
     else{
          d_target = s_target;
     }

     if (d_target > 1){
          System.out.println("You were "+Math.round(d_target * 100) / 100.0d+" meters off");
     }
[B]}[/B]
System.out.println("Well done you hit the target");
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#21
Is this what you want?
Code:
 . . .

[B]double d_target=2;[/B]

 . . . 

x_target = 1 + (Math.round(100 * Math.random() * 100)/100.0d);
[B]while (d_target > 1) {[/B]
     System.out.println("Your target is " +x_target+ " meters away");
     System.out.println();

     System.out.println("How much power will you pull the bow with: ");
     P = input.nextDouble();
     System.out.println();

     System.out.println("At what angle will you shoot your arrow: ");
     theta = input.nextDouble();
     System.out.println();
     
     u = Math.sqrt((2 * P * t_bow) / m);

     t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

     x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

     s_target = x_target - x;

     if (s_target < 0){
          d_target = s_target * -1;
     }
     else{
          d_target = s_target;
     }

     if (d_target > 1){
          System.out.println("You were "+Math.round(d_target * 100) / 100.0d+" meters off");
     }
[B]}[/B]
System.out.println("Well done you hit the target");
Couldn't get what you wrote to work. However that helped me learn the do-while thing, so thank you.:toast:

Here's my awesome game:
import java.util.Scanner;

public class archery{
public static void main(String args[]){
Scanner input = new Scanner(System.in);

double x_target;
double P;
double theta;
double u;
double t;
double x;
double s_target;
double d_target;
double m = 1.0;
double t_bow = 1.0;

System.out.println("Let's shot some arrows!");

x_target = 1 + (Math.round(100 * Math.random() * 100)/100.0d);
System.out.println("Your target is " +x_target+ " meters away");
System.out.println();

do {
System.out.println("How much power will you pull the bow with: ");
P = input.nextDouble();
System.out.println();

System.out.println("At what angle will you shoot your arrow: ");
theta = input.nextDouble();
System.out.println();

u = Math.sqrt((2 * P * t_bow) / m);

t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

s_target = x_target - x;

if (s_target < 0){
d_target = s_target * -1;
}
else{
d_target = s_target;
}
if (d_target > 1){
System.out.println("You were "+Math.round(d_target * 100) / 100.0d+" meters off");
System.out.println();
}
else {
System.out.println("Well done you hit the target");
}
}
while (d_target > 1);


}
}
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#22
What would be a logical step up from the archery game? Preferably something that doesn't require much imagination (so no text adventure).
 
Joined
Aug 17, 2009
Messages
1,577 (0.52/day)
Likes
461
Location
Los Angeles/Orange County CA
System Name Vulcan
Processor i6 6600K
Motherboard GIGABYTE Z170X UD3
Cooling Thermaltake Frio Silent 14
Memory 16GB Corsair Vengeance LPX 16GB (2 x 8GB)
Video Card(s) ASUS Strix GTX 970
Storage Mushkin Enhanced Reactor 1TB SSD
Display(s) QNIX 27 Inch 1440p
Case Fractal Design Define S
Audio Device(s) On Board
Power Supply Cooler Master V750
Software Win 10 64-bit
#23
My advice is to learn Perl or Python or even C.

I hate Java. It's buggy as hell.
 
Joined
Jul 26, 2010
Messages
1,655 (0.61/day)
Likes
729
Location
Philly
System Name Primary Rig
Processor Phenom II X4 B50 @ 3.7GHz
Motherboard Biostar TA790GX 128M
Cooling Sunbeam CR-CCTF 120mm , 6x120mm, MOS-C1
Memory 2x2GB Kingston HyperX 1066 @ 800 4-4-4-12
Video Card(s) Sapphire HD 5830 800/1000 @ 885/1225
Storage 320GB, 400GB, 500GB, 1.5TB
Display(s) Hannspree HF259
Case CM 690
Power Supply OCZ 850W
Benchmark Scores 3Dmark06: 18545/5219 CPU Mark 7.0: 3911.2 Cinebench R10: 11826/3359 x264 HD 2.0: 75.6/23.9
#24
What would be a logical step up from the archery game? Preferably something that doesn't require much imagination (so no text adventure).
Seeing as how 99% of the world does not use console applications, I'd suggest making a GUI for your archery game. The structure of GUI code is fairly similar in most languages, meaning they're mostly event driven. Here's the (rather poorly written IMO) official tutorial.

I'd create a simple window with a couple edit controls (text boxes) for inputting theta/P and a button to start the simulation. Then I'd plot the arrows path and show the origin and target.

It sounds complicated but it's actually very easy.
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#25
What am I doing wrong with this piece of code?
import java.util.*;

public class vectortest {

public static void main(String args[]){
Vector v = new Vector(5, 5);

while (int i = 0; i < 25; i++){
v.add(i, i);
}

int k = (int)v.get(4);
System.out.println(k);
}
}
I'm trying to make a 25 places big vector with each place containing an integer with the same value as the place itself (hence the (i, i)). Then it should display the 5th int in the vector.
The errors: