Help building basic println/string out program.

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 788 Views - Last Post: 10 April 2012 - 10:59 PM Rate Topic: -----

#1 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Help building basic println/string out program.

Posted 10 April 2012 - 06:20 PM

I am trying to build a simple java program that prints multiple lines of text on the screen.

I don't have my book for class yet and am getting destroyed over here. I'm stumbling around in the dark here - if anyone knows how to fix this mess of code then, please, help.

Thank you in advance for any help anyone has to offer. Much appreciated!

public class Global
{

	public static void main()

	String Bang = "Java program\n"
				 + "{ and }\n"
				 + "yeee\n"
				 + "\n"
				 + "System.out.println\n"
				 + "( and )\n"
				 + "String\n"
				 + ""weeee(mmk\" instead!)";
	
		System.out.println{""};

}


Is This A Good Question/Topic? 0
  • +

Replies To: Help building basic println/string out program.

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 06:29 PM

Why have you put System.out.Println in a String?
You're right, this is a bit of a mess. What are you trying to do with this code?

You could just call System.out.Println on the String Bang, like so:
System.out.Println(Bang);

EDIT: actually, I don't know.

This post has been edited by DimitriV: 10 April 2012 - 06:37 PM

Was This Post Helpful? 0
  • +
  • -

#3 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 06:33 PM

I am trying to have the blue text print to the command prompt when the code is run.

This EXACT text needs to be printed:

{ and }
yeee
System.out.println
( and )
String
"weeee(mmk\" instead!)

My teachers are haters and threw in a bunch of weird punctuation.

I think it is all supposed to be printed from println commands but a giant string seems to be easier...

This post has been edited by macosxnerd101: 10 April 2012 - 08:42 PM
Reason for edit:: Made edits per OP request

Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 06:39 PM

This will help regarding edit times:
http://www.dreaminco...-to-edit-times/
But in the meantime, click the Report button near the bottom left of the posts you made and politely request a mod to edit the post for you :)
Was This Post Helpful? 0
  • +
  • -

#5 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 06:55 PM

I have made the change you suggested so that the println function runs the Bang string. Here is the error I am receiving upon compiling.

Process started >>>
java.lang.NoClassDefFoundError: 1) P54/E3
Caused by: java.lang.ClassNotFoundException: 1) P54.E3
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: 1) P54.E3. Program will exit.
Exception in thread "main" <<< Process finished.
================ READY ================


I assume that there are still quite a few errors with the code. Here is what I currently am working with:

public class Global
{

	public static void main()

	System.out.Println{Bang};
	
	String Bang = "Java program\n"
				 + "{ and }\n"
				 + "yeee\n"
				 + "\n"
				 + "System.out.println\n"
				 + "( and )\n"
				 + "String\n"
				 + ""weeee(mmk\" instead!)";
	
		

}


This is the entire code sheet that I have. My best guess is that I am missing a Main class?
Was This Post Helpful? 0
  • +
  • -

#6 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:00 PM

For the main void, it needs to look like this:
public static void main() {
//code
}


Was This Post Helpful? 0
  • +
  • -

#7 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:03 PM

I just included the brackets and ran it. Still will not run. Any more ideas?

Thanks for the continued help.
Was This Post Helpful? 0
  • +
  • -

#8 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:09 PM

Maybe it is worth a look here. I think I've just made a mess here.

Perhaps it must look like this:
public static void main(String[] args){
//code
}


This post has been edited by DimitriV: 10 April 2012 - 07:10 PM

Was This Post Helpful? 0
  • +
  • -

#9 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:19 PM

Still not running....

public class Global
{

	public static void main(String[] args)
	{

		System.out.Println{Bang};
	
		String Bang = "Java program\n"
					+ "{ and }\n"
					+ "yeee\n"
					+ "\n"
					+ "System.out.println\n"
					+ "( and )\n"
					+ "String\n"
					+ ""weeee(mmk\" instead!)";
	
		
	}
}

Was This Post Helpful? 0
  • +
  • -

#10 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:23 PM

Why are you calling Println on Bang before its even declared? Put it after you declare bang!
String Bang = "whatever";
//PUT IT HERE
System.out.Print(Bang);



Is it still coming up with errors?
Was This Post Helpful? 0
  • +
  • -

#11 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:25 PM

Still errors...

Also, I am not 100% sure I know how to compile correctly. Using notepad++. But chances are the code is bad.

public class Global
{

	public static void main(String[] args)
	{

		
	
		String Bang = "Java program\n"
					+ "{ and }\n"
					+ "yeee\n"
					+ "\n"
					+ "System.out.println\n"
					+ "( and )\n"
					+ "String\n"
					+ ""weeee(mmk\" instead!)";
					
		System.out.Println{Bang};
	
		
	}
}

Was This Post Helpful? 0
  • +
  • -

#12 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:28 PM

This line:
+ ""weeee (mmk\" instead!)" 

Is the second quote meant to be printed? If so replace it with this:
+ "\"weeee (mmk\" instead!)"

Was This Post Helpful? 0
  • +
  • -

#13 FEAST  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 10-April 12

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:32 PM

+ "\"weeee (mmk\" instead!)"


Yes, but I will change it to this:

+ "\"weeee (mmk\\" instead!)"


Because I need it to print exactly like this:

"weeee (mmk\" instead!)
Was This Post Helpful? 0
  • +
  • -

#14 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:35 PM

Needs to look like this:
"\"weeee (mmk\\\" instead!)"


Was This Post Helpful? 0
  • +
  • -

#15 floppyspace  Icon User is offline

  • D.I.C Regular

Reputation: 48
  • View blog
  • Posts: 254
  • Joined: 04-February 10

Re: Help building basic println/string out program.

Posted 10 April 2012 - 07:40 PM

First do yourself a favour and get an IDE (I would suggest eclipse), this will compile and run your program without changing the .java to a .class on the command line.

your code is close

public class Global // first use lower case for the class name
{

	public static void main(String[] args)
	{

		
	
		String Bang = "Java program\n"
					+ "{ and }\n"
					+ "yeee\n"
					+ "\n"
					+ "System.out.println\n"
					+ "( and )\n"
					+ "String\n"
					+ "weeee(mmk\" instead!)";
					
		System.out.println(Bang); // u used parenthesis 
	                                 // it is lowercase p for println
		
	}
}



If you really want to learn how to run from command line I can post some info about it but there is something on DIC (can not recall page atm).

Have a read, Dimitriv has a link to a page check out part 3 and 4 they will help make some more sense for variables and the use.

If you do not mind watching videos go to youtube and find newboston and check his java for begginers there are some 87 vids or so.

Cheers

This post has been edited by floppyspace: 10 April 2012 - 07:41 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2