7 Replies - 232 Views - Last Post: 08 February 2018 - 02:52 AM Rate Topic: -----

#1 tlclayton1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-January 18

Java program won't compile even though I have no error messages

Posted 07 February 2018 - 03:59 PM

public class PhraseOmatic {
	public static void main (String[] args) {
		//make 3 sets of words to choose from. Add your own!
		String[] wordListOne = {"24/7", "multiTier","30,000 foot", "B-to-B", "win-win", "front-end", "web-based", "pervasive", "smart", "six sigma", 
		"critical-path", "dynamic"};
		
		String[] wordListTwo = {"empowered", "sticky", "value-added", "oriented", "centric", "distributed", "clustered", "branded", "outside-the-box", "positioned",
		"networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"};
		
		String[] wordListThree = {"process", "tipping-point", "solution", "architecture", "core competency", "strategy", "mindshare", "portal", "space", "vision", 
		"paradigm", "mission"};
		
		//find out how many words are in each list.
		int oneLength = wordListOne.length;
		int twoLength = wordListTwo.length;
		int threeLength = wordListThree.length;
		
		//generate three random numbers 
		int rand1 = (int) (Math.random() * oneLength);
		int rand2 = (int) (Math.random() * twoLength);
		int rand3 = (int) (Math.random() * threeLength);
		
		//now build a phrase
	String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree [rand3];
	
	    //System.out.print("What we need is a " + phrase);
	}
}
	
		
		




Is their anything I'm missing?

Is This A Good Question/Topic? 0
  • +

Replies To: Java program won't compile even though I have no error messages

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 14031
  • View blog
  • Posts: 56,118
  • Joined: 12-June 08

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 04:03 PM

I am confused. What do you mean there's no error messages? If it won't compile it usually tells you.
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5201
  • View blog
  • Posts: 13,944
  • Joined: 18-April 07

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 04:28 PM

It is probably because it has no errors and yet he doesn't actually print anything. Uncomment your last print statement there and you will see it is working fine. It compiles and just not displaying output.

P.S. I took your code, went to an online Java compiler, plugged it in, uncommented the last line and Voila! worked fine.

This post has been edited by Martyr2: 07 February 2018 - 04:29 PM

Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3540
  • View blog
  • Posts: 16,130
  • Joined: 20-September 08

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 04:42 PM

Quote

Java program won't compile
It will ;)
(some of these comments have already been made in so many words)
a. You can't have an app that won't compile without error messages
b. It won't run if it doesn't compile

I suspect you're using some kind of IDE. We're you not doing so, you'd be able to distinguish between compilation and running a Java app. The trouble is that there will be other important stuff that's escaping your notice by using an IDE, which is why my opinion is that they shouldn't be used until you've got a good command of Java fundamentals.

At the most, you should be saying "my app runs but there's no output". And the reason for that, as has been said above, is that you've commented out the only thing in your app that would give you any output
Was This Post Helpful? 2
  • +
  • -

#5 tlclayton1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-January 18

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 07:05 PM

View PostMartyr2, on 07 February 2018 - 04:28 PM, said:

It is probably because it has no errors and yet he doesn't actually print anything. Uncomment your last print statement there and you will see it is working fine. It compiles and just not displaying output.

P.S. I took your code, went to an online Java compiler, plugged it in, uncommented the last line and Voila! worked fine.



When you say uncommented the last line do you mean eliminate it all together. I'm using Notepad ++ and windows Powershell if that makes any difference.
Was This Post Helpful? 0
  • +
  • -

#6 tlclayton1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-January 18

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 07:18 PM

View Postg00se, on 07 February 2018 - 04:42 PM, said:

Quote

Java program won't compile
It will ;)/>
(some of these comments have already been made in so many words)
a. You can't have an app that won't compile without error messages
b. It won't run if it doesn't compile

I suspect you're using some kind of IDE. We're you not doing so, you'd be able to distinguish between compilation and running a Java app. The trouble is that there will be other important stuff that's escaping your notice by using an IDE, which is why my opinion is that they shouldn't be used until you've got a good command of Java fundamentals.

At the most, you should be saying "my app runs but there's no output". And the reason for that, as has been said above, is that you've commented out the only thing in your app that would give you any output



g00se,
Thank you for your help I just removed the last line that was commented and it gave the output. Thank all of you for your help.
Was This Post Helpful? 0
  • +
  • -

#7 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 691
  • View blog
  • Posts: 5,267
  • Joined: 25-December 13

Re: Java program won't compile even though I have no error messages

Posted 07 February 2018 - 07:19 PM

Quote

uncommented the last line

I think that means removing the // at the start of line 26 so the statement is no longer a comment.
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3540
  • View blog
  • Posts: 16,130
  • Joined: 20-September 08

Re: Java program won't compile even though I have no error messages

Posted 08 February 2018 - 02:52 AM

Quote

I'm using Notepad ++ and windows Powershell if that makes any difference.

In that case, i'm surprised you said it "won't compile". You do realise the following?
a. if there is no output from compilation it has compiled correctly
b. if there IS output, it will be compilation errors

Otherwise, it's good that you're using those tools at the moment

btw, "uncomment" means to remove the comment and therefore reactivate for compilation
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1