Difference between revisions of "Return Array"
Line 38: | Line 38: | ||
int temp; | int temp; | ||
− | temp = combineNumber(204, 4881234); | + | temp = combineNumber(204, 4881234); // instead of storing in temp you could also just print this directly |
System.out.print(temp); | System.out.print(temp); | ||
Line 50: | Line 50: | ||
public static int combineNumber( int areaCode, int phoneNumber ) | public static int combineNumber( int areaCode, int phoneNumber ) | ||
{ | { | ||
− | + | areaCode = areaCode * 10000000; | |
− | + | ||
− | areaCode = areaCode * 10000000 | + | |
− | + | ||
− | + | ||
− | return | + | return (areaCode + phoneNumber); |
} | } | ||
</pre> | </pre> | ||
Line 74: | Line 70: | ||
public static int combineNumber( int areaCode, int phoneNumber ) | public static int combineNumber( int areaCode, int phoneNumber ) | ||
{ | { | ||
− | + | areaCode = areaCode * 10000000; | |
− | + | ||
− | areaCode = areaCode * 10000000 | + | |
− | + | ||
− | + | ||
− | return | + | return (areaCode + phoneNumber); |
} | } | ||
</pre> | </pre> | ||
}} | }} |
Revision as of 12:27, 1 April 2010
Back to the Program-A-Day homepage
ProblemWrite a method which will take a three digit area code and a phone number and combine these into one value. Print this value in main.
|
SideSectionTitle
An image or By Students section | |
---|---|---|
SolutionThe solution...
To solve this problem we are going to create a skeleton structure. We know that we will have two methods: main & combineNumber. We know that combineNumber will accept two integers and return an integer:
public static void main() { } public static int returnArray( int areaCode, int phoneNumber ) { }
public static void main() { int temp; temp = combineNumber(204, 4881234); // instead of storing in temp you could also just print this directly System.out.print(temp); }
public static int combineNumber( int areaCode, int phoneNumber ) { areaCode = areaCode * 10000000; return (areaCode + phoneNumber); }
public static void main() { int temp; temp = combineNumber(204, 4881234); System.out.print(temp); } public static int combineNumber( int areaCode, int phoneNumber ) { areaCode = areaCode * 10000000; return (areaCode + phoneNumber); } | ||
CodeSolutionCode goes here. Please DO NOT put your code in <pre> tags! |