Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Simple Java program? (Loops)?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
nothing4me
Newbie cheater
Reputation: 0

Joined: 27 Dec 2006
Posts: 10

PostPosted: Wed Oct 29, 2008 4:47 pm    Post subject: Simple Java program? (Loops)? Reply with quote

I need to create this using loops:
(The underlines are spaces)
____*
___***
__*****
_*******
*********
*********
_*******
__*****
___***
____*

Can anyone do it and post the source code? Sad

Here is a chart in case you don’t feel like counting:
Row Spaces Stars
1 4 1
2 3 3
3 2 5
4 1 7
5 0 9
6 0 9
7 1 7
8 2 5
9 3 3
10 4 1
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Wed Oct 29, 2008 5:20 pm    Post subject: Reply with quote

Not your personal homework-monkeys. Try learning something.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Wed Oct 29, 2008 7:00 pm    Post subject: Reply with quote

why not do it in batch o.o

:start
echo ____*
echo ___***
echo __*****
echo _*******
echo *********
echo *********
echo _*******
echo __*****
echo ___***
echo ____*
goto :start

win o.o

_________________
Back to top
View user's profile Send private message AIM Address
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Thu Oct 30, 2008 5:05 pm    Post subject: Reply with quote

yoyonerd wrote:
why not do it in batch o.o
win o.o


Your program prints it repeatedly, thats not what he wants. He wants to print it once using loops, duh.

for(int i; i < 1; i++) {
System.out.println("____*");
System.out.println("echo ___***");
System.out.println("echo __*****");
System.out.println("echo _*******");
System.out.println("echo *********");
System.out.println("echo *********");
System.out.println("echo _*******");
System.out.println("echo __*****");
System.out.println("echo ___***");
System.out.println("echo ____* ");
}

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Thu Oct 30, 2008 6:13 pm    Post subject: Reply with quote

Single look at your chart for patterns the answers of stars are always odd.. and the counter could start at X.. so just start it at 4 now you understand the pattern

you will be going to use 2 for loops to make it look good.. with one counting down and other counting up

or you could use one while loop with a boolean and add a if statements if(counter == 0) then
boolean = true;

if(boolean) then
counter++
counterVal-= 2;
else
counter--;
counterVal+=2;

I'm 100% sure the teacher wants you to use a algorithm to solve this not just echo it out.. or u will get a low joe..

Anyways if you can't do this in a algorithm then u shouldnt be programming

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
nothing4me
Newbie cheater
Reputation: 0

Joined: 27 Dec 2006
Posts: 10

PostPosted: Thu Oct 30, 2008 6:20 pm    Post subject: Reply with quote

I already have it solved, thanks anyway.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Oct 30, 2008 6:54 pm    Post subject: Reply with quote

Code:
#include <iostream>
const int width_max = 10;
int width = 10;
int count = 0;

int main(){
   do{
      int difference = (width / 2) - 1;
      for(int i = 0; i < difference; i++){
         std::cout << " ";
      }width--;
      for(int i = 0; i < (width_max - width); i++){
         std::cout << "*";
      }std::cout << "\n";
   }while(width > 0);
   return 0;
}


I then realized I had not taken fractions into account, and that I was doing it a stupid way to begin with, got bored, and stopped. Don't feel like actually thinking for a few minutes now. Neutral



edit: Figured it out woop.

Code:
#include <iostream>
int main()
{
   int size, count = 0;
   std::cin >> size;
   for (int i = 0; size > i; count++, size--){
      for (int i = 0; size > i; i++){
         std::cout << " ";
      }
      for (int i = 0; (2 * count) >= i; i++){
         std::cout << "*";
      }std::cout << "\n";
   }
   return 0;
}


Last edited by hcavolsdsadgadsg on Thu Oct 30, 2008 10:10 pm; edited 2 times in total
Back to top
View user's profile Send private message
nothing4me
Newbie cheater
Reputation: 0

Joined: 27 Dec 2006
Posts: 10

PostPosted: Thu Oct 30, 2008 7:27 pm    Post subject: Reply with quote

slovach wrote:
Code:
#include <iostream>
const int width_max = 10;
int width = 10;
int count = 0;

int main(){
   do{
      int difference = (width / 2) - 1;
      for(int i = 0; i < difference; i++){
         std::cout << " ";
      }width--;
      for(int i = 0; i < (width_max - width); i++){
         std::cout << "*";
      }std::cout << "\n";
   }while(width > 0);
   return 0;
}


I then realized I had not taken fractions into account, and that I was doing it a stupid way to begin with, got bored, and stopped. Don't feel like actually thinking for a few minutes now. Neutral
That's not Java, but thanks for trying anyway. Smile
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Fri Oct 31, 2008 3:32 am    Post subject: Reply with quote

Now this is spoon feeding. He's given you the code, now just convert it.
Surely you can tell where the loops are in that code etc.

_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
nothing4me
Newbie cheater
Reputation: 0

Joined: 27 Dec 2006
Posts: 10

PostPosted: Fri Oct 31, 2008 4:44 am    Post subject: Reply with quote

--Pillboi-- wrote:
Now this is spoon feeding. He's given you the code, now just convert it.
Surely you can tell where the loops are in that code etc.
I don't need it... Sad

Why don't people read posts? xD I already did it myself!
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Fri Oct 31, 2008 7:11 am    Post subject: Reply with quote

edit: Figured it out woop.

Code:
#include <iostream>
int main()
{
   int size, count = 0;
   std::cin >> size;
   for (int i = 0; size > i; count++, size--){
      for (int i = 0; size > i; i++){
         std::cout << " ";
      }
      for (int i = 0; (2 * count) >= i; i++){
         std::cout << "*";
      }std::cout << "\n";
   }
   return 0;
}
[/quote]

I think you are missing the last half (this broke my head..., but with the help of your code, i figured it out at last...))


Code:
#include <iostream>

int main()
{
   int size, count = 0;
   std::cin >> size;
   for (int i = 0; size > i; count++, size--){
      for (int i = 0; size > i; i++){
         std::cout << " ";
      }
      for (int i = 0; (2 * count) >= i; i++){
         std::cout << "*";
      }std::cout << "\n";
   }
   count--;
   for (int i = count; size < i; size++, count--){
      for (int i = 0; size+2 > i; i++){
         std::cout << " ";
      }
      for (int i = 0; (count * 2 -1) > i; i++){
         std::cout << "*";
      }std::cout << "\n";   
   }
   std::cin.sync();
   std::cin.ignore();
   return 0;
}
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sat Nov 01, 2008 6:33 am    Post subject: Reply with quote

Here's my old code, maybe someone of you recognizes it :D

Code:
import java.util.Random;
import java.io.*;

class printtt {
        public static void main(String[] args) {

                /* Let's do one randomly */

                Random generator = new Random();
                int rand = generator.nextInt(50);
      rand += 50;

      /* And one by user input */
                System.out.print("Width: "); /* Get the width */

                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String wid[] = {null, "\u0049", "\u0044\u0049\u0044\u004E\u0027\u0054", "\u004D\u0041\u004B\u0045", "\u0054\u0048\u0049\u0053", "\u004D\u0059\u0053\u0045\u004C\u0046"};
                try {
                        wid[0] = br.readLine();
                } catch (IOException ioe) {
                        System.out.println("Error");
                }


                /* DO THE PRINTING */
                for( int i = 0; i<rand; ++i) { int j = generator.nextInt(5) + 1; System.out.println(wid[j]); }
        }
}


/me waits some random stupid kid (hackersrule or something) who knows nothing to derep me with a reason "he did someone's homework!" :)
Back to top
View user's profile Send private message
nothing4me
Newbie cheater
Reputation: 0

Joined: 27 Dec 2006
Posts: 10

PostPosted: Sat Nov 01, 2008 10:35 am    Post subject: Reply with quote

Jani wrote:
Here's my old code, maybe someone of you recognizes it Very Happy

Code:
import java.util.Random;
import java.io.*;

class printtt {
        public static void main(String[] args) {

                /* Let's do one randomly */

                Random generator = new Random();
                int rand = generator.nextInt(50);
      rand += 50;

      /* And one by user input */
                System.out.print("Width: "); /* Get the width */

                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String wid[] = {null, "\u0049", "\u0044\u0049\u0044\u004E\u0027\u0054", "\u004D\u0041\u004B\u0045", "\u0054\u0048\u0049\u0053", "\u004D\u0059\u0053\u0045\u004C\u0046"};
                try {
                        wid[0] = br.readLine();
                } catch (IOException ioe) {
                        System.out.println("Error");
                }


                /* DO THE PRINTING */
                for( int i = 0; i<rand; ++i) { int j = generator.nextInt(5) + 1; System.out.println(wid[j]); }
        }
}


/me waits some random stupid kid (hackersrule or something) who knows nothing to derep me with a reason "he did someone's homework!" Smile
BUT I ALREADY DID IT! T_T_T_T_T_T_T


Why doesn't anyone read my posts??? Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites