| | |
Number sequence
![]() |
•
•
Join Date: Oct 2007
Posts: 19
Reputation:
Solved Threads: 0
Ok, I am totally confused - probably because I've been staring at my computer for hours, but I need some guidance (not for homework, just my own personal knowlegde)...
Here's the output I'm trying to achieve:
012343210
001234321
000123432
000012343
000001234
...And I know I need to use a for loop. I would know how to get it to count up to 4, but to then count down from 4, I get confused there (also adding the 0's for each new line, etc.). Anyone have any ideas? It's probably an easy setup, just one detail that's not clicking in my head, but it's just wracking my brain, so I figured someone could rather "tutor" me on this quick. Thanks!
Here's the output I'm trying to achieve:
012343210
001234321
000123432
000012343
000001234
...And I know I need to use a for loop. I would know how to get it to count up to 4, but to then count down from 4, I get confused there (also adding the 0's for each new line, etc.). Anyone have any ideas? It's probably an easy setup, just one detail that's not clicking in my head, but it's just wracking my brain, so I figured someone could rather "tutor" me on this quick. Thanks!
•
•
Join Date: Sep 2009
Posts: 18
Reputation:
Solved Threads: 3
Agree with previous post.
Basically:
-Create an int array lengthed 5 that has the values from 0 to 4
-use for loop:
Havn't complied this, so double check. But I'm sure it'll work =)!
Goodluck =)
please mark as solved if this its what you were looking for.
Basically:
-Create an int array lengthed 5 that has the values from 0 to 4
-use for loop:
Java Syntax (Toggle Plain Text)
for(int a=0; 0<arrayName.length(); a++) { if(count==9) { count=0; System.out.println(""); } count++; System.out.print(arrayName[a]); } if(count==9) { count=0; System.out.println(""); } count++; System.out.print("0"); for(int a=4; 0=<a; a--) { if(count==9) { count=0; System.out.println(""); } count++; System.out.print(arrayName[a]); }
Havn't complied this, so double check. But I'm sure it'll work =)!
Goodluck =)
please mark as solved if this its what you were looking for.
Last edited by roswell67; Sep 16th, 2009 at 2:48 am.
•
•
Join Date: Sep 2009
Posts: 18
Reputation:
Solved Threads: 3
mmm create a new thread so you can get exclusive help as its not the same thing.
•
•
Join Date: Sep 2009
Posts: 14
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
import java.io.Serializable; public class MyObjectToSerialize implements Serializable { private static final long serialVersionUID = 1L; private int autogeneratedNumber; public MyObjectToSerialize(int autogeneratedNumber) { this.autogeneratedNumber = autogeneratedNumber; } public String toString() { return autogeneratedNumber + ""; } public int getAutogeneratedNumber() { return autogeneratedNumber; } public void setAutogeneratedNumber(int autogeneratedNumber) { this.autogeneratedNumber = autogeneratedNumber; } } import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.DecimalFormat; import java.text.NumberFormat; public class ObjectSerialization { private static void saveObject(Serializable object, String filename) throws IOException { ObjectOutputStream objstream = new ObjectOutputStream( new FileOutputStream(filename)); objstream.writeObject(object); objstream.close(); } private static Object loadObject(String filename) throws ClassNotFoundException, IOException { ObjectInputStream objstream = new ObjectInputStream( new FileInputStream(filename)); Object object = objstream.readObject(); objstream.close(); return object; } public static void main(String[] args) { // MyObjectToSerialize original = new MyObjectToSerialize(0); try { // saveObject(original, "C:/serializable.ser"); MyObjectToSerialize loaded = (MyObjectToSerialize) loadObject("C:/serializable.ser"); loaded.setAutogeneratedNumber(loaded.getAutogeneratedNumber() + 1); saveObject(loaded, "C:/serializable.ser"); System.out.println(String.format("%08d", loaded.getAutogeneratedNumber())); } catch (Exception e) { e.printStackTrace(); } } }
SNIP
Last edited by happygeek; Sep 30th, 2009 at 5:54 am. Reason: spam deleted
•
•
Join Date: Jun 2009
Posts: 99
Reputation:
Solved Threads: 4
ok. I have solved your "0" problem
Now let me see how much u have tried before i give u the solution
JAVA Syntax (Toggle Plain Text)
class newbie { public static void main(String args[]) { int i,j; for(i=0;i<6;i++) { for(j=0;j<i;j++) { System.out.print(0); } System.out.println(); } } }
Now let me see how much u have tried before i give u the solution
![]() |
Similar Threads
- Prime Number (Posting Games)
- I need help writing a program using Fibonacci sequence (C++)
- Having problem generating Fibonacci sequence (C)
- help: string and random number generator Questions (C++)
- Programs for Barcodes (Computer Science)
- Random sequence in an array? (C++)
- shell script for number sequence--- anybody help me? (Shell Scripting)
- Need to know how to create a database that will generate a random number (Database Design)
- turning and int into seperate digits (C++)
Other Threads in the Java Forum
- Previous Thread: Save a map
- Next Thread: Confirmation Failing
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php print problem program programming project recursion repositories scanner scrollbar server set size sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows






