Creating a method/function in java

Ascending numbers 0 to 9

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1109 Views - Last Post: 30 June 2009 - 05:22 PM Rate Topic: -----

#1 Gsirtak  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 30-June 09

Creating a method/function in java

Posted 30 June 2009 - 08:56 AM

Ascending numbers with a method/function.

Hi,

I need a little help programming a java code creating a method/function to ascend numbers 0 to 9 with smallest to the largest.

Thank you,
George



class Ascending
{
public static void main(String[] args)
{
int num1 = 0;
int num2 = 0;
int num3;

  for (num1 = 1; num1 < 10; num1++)
	System.out.println(num1);

  for (num2 = 1; num2 < 10; num1++)
	System.out.println(num2);

  num3 = num2 % num1;

  if (num3 == 0)
	System.out.println("The prime numbers are " + num1);
  else
	System.out.println("The prime numbers are " + (num1 += 1));
  }
}

This post has been edited by Gsirtak: 30 June 2009 - 09:00 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Creating a method/function in java

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Creating a method/function in java

Posted 30 June 2009 - 08:58 AM

[rules]
[/rules]
Was This Post Helpful? 0
  • +
  • -

#3 kmangold  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 167
  • Joined: 24-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:00 AM

Here you go.

public void foobar() {
	System.out.println("0");
	System.out.println("1");
	System.out.println("2");
	System.out.println("3");
	System.out.println("4");
	System.out.println("5");
	System.out.println("6");
	System.out.println("7");
	System.out.println("8");
	System.out.println("9");
}

Was This Post Helpful? 1
  • +
  • -

#4 Tanira  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 102
  • Joined: 30-May 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:07 AM

View Postkmangold, on 30 Jun, 2009 - 08:00 AM, said:

Here you go.

public void foobar() {
	System.out.println("0");
	System.out.println("1");
	System.out.println("2");
	System.out.println("3");
	System.out.println("4");
	System.out.println("5");
	System.out.println("6");
	System.out.println("7");
	System.out.println("8");
	System.out.println("9");
}


for(int q = -1; q < 10; q++){
System.out.println(q);
}


I like this better

This post has been edited by Tanira: 30 June 2009 - 09:09 AM

Was This Post Helpful? 1
  • +
  • -

#5 kmangold  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 167
  • Joined: 24-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:17 AM

I do too. But I wanted to use the simplest form of Java, static everything! Lol, why are you starting from -1?
Was This Post Helpful? 0
  • +
  • -

#6 Gsirtak  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 30-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:20 AM

View Postkmangold, on 30 Jun, 2009 - 08:00 AM, said:

Here you go.

public void foobar() {
	System.out.println("0");
	System.out.println("1");
	System.out.println("2");
	System.out.println("3");
	System.out.println("4");
	System.out.println("5");
	System.out.println("6");
	System.out.println("7");
	System.out.println("8");
	System.out.println("9");
}



View Postkmangold, on 30 Jun, 2009 - 08:00 AM, said:

Here you go.

public void foobar() {
	System.out.println("0");
	System.out.println("1");
	System.out.println("2");
	System.out.println("3");
	System.out.println("4");
	System.out.println("5");
	System.out.println("6");
	System.out.println("7");
	System.out.println("8");
	System.out.println("9");
}



Thanks Kevin. I appreciate your time.
George
Was This Post Helpful? 0
  • +
  • -

#7 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 916
  • View blog
  • Posts: 3,208
  • Joined: 12-May 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:21 AM

View Postkmangold, on 30 Jun, 2009 - 12:17 PM, said:

I do too. But I wanted to use the simplest form of Java, static everything! Lol, why are you starting from -1?


Static everything is often the last thing you want to do in an object oriented language.
Was This Post Helpful? 0
  • +
  • -

#8 Gsirtak  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 30-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:22 AM

View PostTanira, on 30 Jun, 2009 - 08:07 AM, said:

View Postkmangold, on 30 Jun, 2009 - 08:00 AM, said:

Here you go.

public void foobar() {
	System.out.println("0");
	System.out.println("1");
	System.out.println("2");
	System.out.println("3");
	System.out.println("4");
	System.out.println("5");
	System.out.println("6");
	System.out.println("7");
	System.out.println("8");
	System.out.println("9");
}


for(int q = -1; q < 10; q++){
System.out.println(q);
}


I like this better


Thanks for the help Tamira!
George
Was This Post Helpful? 0
  • +
  • -

#9 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2794
  • View blog
  • Posts: 15,904
  • Joined: 24-September 08

Re: Creating a method/function in java

Posted 30 June 2009 - 09:22 AM

You spelled fubar wrong XD

And I would start from 0 not -1 lol.

for(int i = 0, i < 10, i++) {sout(i);}



Edit: sry, he did say 0-9, not 0-10 XD

This post has been edited by NeoTifa: 30 June 2009 - 09:23 AM

Was This Post Helpful? 0
  • +
  • -

#10 kmangold  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 167
  • Joined: 24-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:23 AM

View Postxclite, on 30 Jun, 2009 - 10:21 AM, said:

View Postkmangold, on 30 Jun, 2009 - 12:17 PM, said:

I do too. But I wanted to use the simplest form of Java, static everything! Lol, why are you starting from -1?


Static everything is often the last thing you want to do in an object oriented language.


Thank you for pointing out the obvious xclite. Do you really think my code post is what I would do?
Was This Post Helpful? 0
  • +
  • -

#11 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 916
  • View blog
  • Posts: 3,208
  • Joined: 12-May 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:26 AM

View Postkmangold, on 30 Jun, 2009 - 12:23 PM, said:

View Postxclite, on 30 Jun, 2009 - 10:21 AM, said:

View Postkmangold, on 30 Jun, 2009 - 12:17 PM, said:

I do too. But I wanted to use the simplest form of Java, static everything! Lol, why are you starting from -1?


Static everything is often the last thing you want to do in an object oriented language.


Thank you for pointing out the obvious xclite. Do you really think my code post is what I would do?


If it wasn't what you would do, don't say it is. If you aren't going to be helpful, don't post.
Was This Post Helpful? 0
  • +
  • -

#12 kmangold  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 167
  • Joined: 24-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:27 AM

The OP already had a solution to his question. There was nothing more to answer.
Was This Post Helpful? 0
  • +
  • -

#13 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 916
  • View blog
  • Posts: 3,208
  • Joined: 12-May 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:30 AM

View Postkmangold, on 30 Jun, 2009 - 12:27 PM, said:

The OP already had a solution to his question. There was nothing more to answer.

You said that's not actually how you would do it, though, so obviously your solution wasn't sufficient. Maybe it's a good thing I pointed out the obvious?
Was This Post Helpful? 0
  • +
  • -

#14 kmangold  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 167
  • Joined: 24-June 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:36 AM

Wow, never mind.
Was This Post Helpful? 0
  • +
  • -

#15 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 916
  • View blog
  • Posts: 3,208
  • Joined: 12-May 09

Re: Creating a method/function in java

Posted 30 June 2009 - 09:41 AM

View Postkmangold, on 30 Jun, 2009 - 12:36 PM, said:

Wow, never mind.


The OP did not have an answer, because you have admitted that your answer was not the best way to do it, and in fact it was hardly an acceptable way to do it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2