Hi everyone, I'm new here and hope you all don't mind me asking this. I have just started my first Java class, the only other one I have taken so far was for writing pseudocodes (not fun) I just want to make sure I'm doing this right and wanted to ask some experts. I do see there are tutorials on here and I will definitely take advantage of those, please don't think I'm asking you to do my homework for me, I do have part of it done, just unsure on if it's right. I'll get there but need help on the way. Thank You in advance!
This is my assignment, not sure if I'm doing it right!!
The first line should display the following text: "Hi, my name is [insert your name]."
The second line should display the following text: "I was born in [insert your birth place].
This is what I have, how do I get the I was born in part in?
1 // My name is.java
2 // Printing multiple lines in a dialog box.
3
4 public class My name is
5 {
6 // main method begins execution of Java application
7 public static void main( String args[] )
8 {
9 System.out.printf( "%s\n%s\n",
10 "My name is", "Cassie!" )
11
12 } // end method main
13
14 } // end class My name is
Just learning
Started by Cassie836, Aug 08 2008 05:22 PM
2 replies to this topic
#1
Posted 08 August 2008 - 05:22 PM
|
|
|
#2
Posted 08 August 2008 - 09:13 PM
Well, one problem and one recommendation.
Problem: Your class name cannot contain white space. Meaning "My name is" is invalid. It needs to be something like "MyNameIs" or "My_name_is"
Recommendation: I prefer to use System.out.println("Hello my name is Cassie!"); rather than your System.out.printf(...)
Problem: Your class name cannot contain white space. Meaning "My name is" is invalid. It needs to be something like "MyNameIs" or "My_name_is"
Recommendation: I prefer to use System.out.println("Hello my name is Cassie!"); rather than your System.out.printf(...)
#3
Posted 09 August 2008 - 04:45 PM
Thank You, I actually ended up doing it completely different but still don't know if I did it right. This is how I did it.....
String temp1 = "My name is";
String temp2 = "Cassie";
String temp3 = "I was born in";
String temp4 = "Flint";
System.out.printf("%s %s \n",temp1,temp2);
System.out.printf("%s %s \n",temp3,temp4);
String temp1 = "My name is";
String temp2 = "Cassie";
String temp3 = "I was born in";
String temp4 = "Flint";
System.out.printf("%s %s \n",temp1,temp2);
System.out.printf("%s %s \n",temp3,temp4);


Sign In
Create Account

Back to top









