Computer Science Canada

A Loop program

Author:  grasshopper [ Mon Mar 29, 2004 4:38 pm ]
Post subject:  A Loop program

i need help writing a program.. i`m just testing loops.. and i`m not sure how to print this but i just want to try.. anyone know the code?

I need to write a program which produces sets of triangles like these:
****
***
**
*
*
**
***
****

- ->I need to allow the user to deteremine how many sets of triangles will be produced.. I know I need this using TextIO...

I started programming this using a `for loop`. and then got stuck....

any suggestions? thanksss

Author:  Tony [ Mon Mar 29, 2004 5:08 pm ]
Post subject: 

well first you'll need a function to compile your line of astrics, similar to turing's repeat

code:

string repeat(int size)
{
  String word = new String;
  word = "";
  for (int i=0;i<size;i++)
  {
    word = word + "*);
  }
  return word
}


now break your patten into decending and addending loops

code:

for (int i=size;i>=1;i--)
{
  System.out.println(repeat(i));
}

for (int i2=1;i2<=size;i2++)
{
  System.out.println(repeat(i2));
}

Author:  wtd [ Mon Mar 29, 2004 6:03 pm ]
Post subject: 

Good suggestion, tony, but instead of using String and + all over the place, use StringBuffer.

code:
String repeat(int size)
{
  StringBuffer word = new StringBuffer("");
  for (int i=0;i<size;i++)
  {
    word.append("*");
  }
  return word.toString();
}


It minimizes the number of temporary String objects created and increases memory efficiency.

Author:  grasshopper [ Tue Mar 30, 2004 8:37 pm ]
Post subject: 

umm.. i`m not worrying about adding the *`s for now because i don`t know where exactly to put that in my code.. i`ll try figuring that out later... but i have another question...

okay this program it`s suppose allow the user to determine how many sets... not how long the set is..
Arrow because in the following code...

code:


import java.io.*;
         
public class triangles
{
  public static void main (String[] args)
   {

 
        int triangles;

 
        System.out.print("Please determine how many sets of triangles you want to have produced: ");
        triangles = TextIO.getlnInt();

       
       
        for (int i=triangles;i>=1;i--)
        {
            System.out.println(i); 
        }

       for (int i2=1;i2<=triangles;i2++)
        {
            System.out.println(i2);
        }

   
    }       //end of main

}          //end of class


the following gets printed out..

Arrow if user determines the number of sets to be 5 the following will print out..

5
4
3
2
1
1
2
3
4
5

Arrow if they chose 4..
4
3
2
1
1
2
3
4

and so on

but want i need it to print is..
Arrow if they chose five..
****
***
**
*
*
**
***
****

****
***
**
*
*
**
***
****

****
***
**
*
*
**
***
****

****
***
**
*
*
**
***
****

****
***
**
*
*
**
***
****


like print that whole set five times if they chose 5...

if anyone can help that would be great.. Very Happy i hope it`s not a lot to ask for.. i`m a beginner at programming loops.. so there is still a lot i need to learn..but i`m sure will all these col programmers i`ll be fine.. wow this is starting to sound g.ay.. i`ll stop..
thanks

Author:  Tony [ Tue Mar 30, 2004 10:29 pm ]
Post subject: 

Confused eh
code:

for (int i=0;i<triangles;i++)
{

     for (int i1=4;i>=1;i--)
        {
            System.out.println(i1);
        }

       for (int i2=1;i2<=4;i2++)
        {
            System.out.println(i2);
        }

}


Wink

Author:  grasshopper [ Thu Apr 01, 2004 9:37 am ]
Post subject:  thanks...

heey.. thanks for the help guys.. but i finally figured it out!!


code:
import java.io.*;
         
public class test
{
  public static void main (String[] args)
   {
        //Variable Declaration
                             
        int triangles;               
       System.out.print("Please determine how many sets of triangles you want to have produced: ");     //prompt for input
        triangles = TextIO.getlnInt();                       //read from keyboard
     
      for (int count=1; count<=triangles; count=count+1)       
       {
        for (int i=4;i>=1;i--)
        {
            for(int j= 1; j<=i; j=j+1)
                     
            System.out.print("*");
            System.out.println ("");
        } //first half of triangle
               
        // begin second half of triangle
        for (int i=1;i<=4;i++)
        {
            for(int j= 1; j<=i; j=j+1)
                     
            System.out.print("*");
            System.out.println ("");
           
        } //second half of triangle
System.out.print("\n");
       }//end of first for statement


    }       //end of main
}          //end of class



Laughing

Author:  wtd [ Thu Apr 01, 2004 3:54 pm ]
Post subject: 

Now put all of the loops and such in a separate method. Putting everything in main is bad, bad bad! Smile

Author:  grasshopper [ Fri Apr 02, 2004 1:16 am ]
Post subject: 

lol is it?.. meh my teacher formatted it like that...

Author:  wtd [ Fri Apr 02, 2004 3:09 pm ]
Post subject: 

Yes. Teachers aren't always right. Wink

code:
class Exercise {
   public static void printStuff() {
     // code here
   }

   public static void main(String[] args) {
      printStuff();
   }
}

Author:  grasshopper [ Sat Apr 03, 2004 2:08 pm ]
Post subject: 

oo i c..
umm okay would you be able to help me with something else..as i`m still a beg. at programming..
i want to try this.. like see the code and see if it can help with something else i need to figure out..but not wanting the code for that..
hmm lets see...
alright.. how about a program that asks the user to enter 10 marks for a student.. umm then print out the student`s average, the maximum mark and the minumum mark..using a loop.. using only one variable to read all marks

can you help
Very Happy

Author:  Dan [ Sat Apr 03, 2004 3:08 pm ]
Post subject: 

well to start you will need 3 varibales.

an int for the max var

an int for the min var

an int for the sum of all the marks


now you will input the 1st mark and sotre it in all 3 vars (max, min, and sum)

next you will make a loop that runs for number of marks to be inputed -1 (becuse you all ready got the 1st mark).

then in the loop you input the number in a temp var. add it to sum and check to see if it is bigger then max or smaller then min. if it is you will set it as the one it is biger or smaller then.

then end the loop and output the max, the min and the sum div the num of marks to get the avg.

Author:  wtd [ Sat Apr 03, 2004 7:54 pm ]
Post subject: 

You'd want something like the following untested program.

code:
import java.lang.*;
import java.io.*;

class Exercise {
   public static BufferedReader keyboard =
      new BufferedReader(new InputStreamReader(
         System.in));

   private class StudentGradeset {
      private double grades[10];
      private int gradesInput;
     
      public StudentGradeSet(double initialGrade = 0.0) {
         grades = new double[10];
         gradesInput = 0;
         int len = grades.length;
         for (int i = 0; i < len; i++)
            grades[i] = initialGrade;
      }

      public double sumOfGrades() {
         double total = 0.0;
         int len = grades.length;
         for (int i = 0; i < len; i++)
            total += grades[i];
         return total;
      }

      public double minGrade() {
         double min = 0;
         int len = grades.length;
         for (int i = 0; i < len; i++)
            if (grades[i] < min)
               min = grades[i];
         return min;
      }

      public double maxGrade() {
         double max = 0;
         int len = grades.length;
         for (int i = 0; i < len; i++)
            if (grades[i] > max)
               max = grades[i];
         return max;
      }

      public double averageGrade() {
         return sumOfGrades() / grades.length;
      }

      private void inputGrade(BufferedReader input) {
         grades[gradesInput++] = Double.parseDouble(input.readLine());
      }

      public void inputGrades(PrintStream output, BufferedReader input) {
         while (gradesInput < grades.length) {
            output.print("Please input a grade: ");
            inputGrade(input);
         }
      }

      public void outputResults(PrintStream output) {
         output.println("Max grade: " + maxGrade());
         output.println("Min grade: " + minGrade());
         output.println("Avg Grade: " + averageGrade());
      }

      public static void main(String[] args) {
         StudentGradeSet grades = new StudentGradeSet();
         grades.inputGrades(System.out, keyboard);
         grades.outputResults(System.out);
      }
}


And just in case seeing the problem solved in other languages can be of help, I've attached some other samples.

Author:  grasshopper [ Sun Apr 04, 2004 3:47 pm ]
Post subject: 

uuuhhh.. what?
i don`t think it was suppose to get that confusing..

Sad

Author:  grasshopper [ Sun Apr 04, 2004 9:14 pm ]
Post subject: 

okaay umm how about i forget that program.. i confused myself..
how about..
A program that asks the user to enter a mark. The program then prints out one line. The word and the mark will be separated by enough dots so that the total line length is 30:
Enter your name: Super
Enter your mark: 95
Super's mark is"¦"¦"¦..95

- ->to print the dots, use System.out.print(".") inside a loop body
- ->might need the following code

code:
String inputString;
Int times;

....

Times= inputstring.length() //times will hold the number of characters in inputString


i don`t know how i`d program that and if i`d use a while or for loop

this is my strcutre so far. (without the public static void main...etc.. etc..)

code:
//Variable Declaration

      String usersName;              //the user's name
      String inputString;
      int times;            //will hold the number of characters in inputString
      int mark;
     
      //Variable Initialization and Input

      System.out.print("Please enter your name: ");     //prompt for input
      usersName = TextIO.getln();                       //read from keyboard
     
      System.out.println("Please enter a mark: ");
      mark = TextIO.getlnInt();

      //Program Processing and Output
      // the process and output i don`t get


Crying or Very sad Crying or Very sad help?

Author:  Dan [ Mon Apr 05, 2004 4:28 pm ]
Post subject: 

TextIO eh? i dont think that is a standered I/O method, u using the Robot java text book by any chance?

any way that dose not matter. This is what i think u need:

code:

                int length = usersName.length() + 11;
               
                if(mark >= 10)
                {
                        length = usersName.length() + 12;
                }
                else if(mark == 100)
                {
                        length = usersName.length() + 13;
                }
               
               
                System.out.print(usersName + "'s mark is");
               
                for     (int i = 0; i < 30-length; i++)
                {
                        System.out.print(".");
                }
               
                System.out.print(mark + "\n");


in this part:

code:

int length = usersName.length() + 11;
               
                if(mark >= 10)
                {
                        length = usersName.length() + 12;
                }
                else if(mark == 100)
                {
                        length = usersName.length() + 13;
                }


length is a var to rep how many chars are in the line minus the "."s. u have to add in 10 for the "'s mark is" part and 1, 2 or 3 for the length of the mark.

the for loop part runs for 30 - the length of the line with out "."s and thous will put in the right number of "."s. some error checking should probly be added to this in case there is - dots or 0 dots needed.


by the way what corse u talking and where? that TextIO is alot like one of the methods in a book i was using for my course.

Author:  wtd [ Mon Apr 05, 2004 9:27 pm ]
Post subject: 

Analysis

Well, first let's analyze the problem.

You need to take two pieces of data (the person's name, and their grade) and output a string containing both values, separated by enough characters (either "." or something else, perhaps).

So we want a function... a black box we push data into, and take information out of. What we put in is a name and a grade, and we get out a string.

code:
String getFormattedString(String name, int grade) {

}


That's just a shell, but when it comes to using the function, that's all we'll need to know. Of course, for it to be useful, you need something between the brackets.

This is what you're asking about. So first we need to figure out the length of the name and the length of the grade (it's probably between 0 and 100, so it might be 1 or 3 printed characters).

code:
String getFormattedString(String name, int grade) {
   int nameLen = name.length();
   int gradeLen;

   if (grade < 10)
      gradeLen = 1;
   else if (grade < 100)
      gradeLen = 2;
   else
      gradeLen = 3;
}


So now we know how how much of those 30 characters the two pieces of data will take up in the end result. Thus we can figure out the number of dots we'll need.

code:
String getFormattedString(String name, int grade) {
   int nameLen = name.length();
   int gradeLen;

   if (grade < 10)
      gradeLen = 1;
   else if (grade < 100)
      gradeLen = 2;
   else
      gradeLen = 3;

   int numOfDots = 30 - nameLen - gradeLen;
}


So now we can just start at 1 and loop up until we get to that amount. We'll create a variable to store the dots in.

code:
String getFormattedString(String name, int grade) {
   int nameLen = name.length();
   int gradeLen;

   if (grade < 10)
      gradeLen = 1;
   else if (grade < 100)
      gradeLen = 2;
   else
      gradeLen = 3;

   int numOfDots = 30 - nameLen - gradeLen;

   String dots = "";

   for (int counter = 1; counter <= numOfDots; counter++)
      dots = dots + "*";
}


Now, to compose the final result, we simple add the dots to the name, and the grade to the end of that. Then we take that string and return it from our function. We "spit" it out the other side of our "black box".

code:
String getFormattedString(String name, int grade) {
   int nameLen = name.length();
   int gradeLen;

   if (grade < 10)
      gradeLen = 1;
   else if (grade < 100)
      gradeLen = 2;
   else
      gradeLen = 3;

   int numOfDots = 30 - nameLen - gradeLen;

   String dots = "";

   for (int counter = 1; counter <= numOfDots; counter++)
      dots = dots + "*";

   String finalResult = name + dots + grade;

   return finalResult;
}


We can then use this as follows:

code:
class Exercise {
   public static String getFormattedString(String name, int grade) {
      int nameLen = name.length();
      int gradeLen;

      if (grade < 10)
         gradeLen = 1;
      else if (grade < 100)
         gradeLen = 2;
      else
         gradeLen = 3;

      int numOfDots = 30 - nameLen - gradeLen;

      String dots = "";

      for (int counter = 1; counter <= numOfDots; counter++)
         dots = dots + "*";
   }

   public static void main(String[] args) {
      String output = getFormattedString("John Doe", 87);
      System.out.println(output);
   }
}


Object-Oriented Design

Further analyzing this problem, the two pieces of data are related. Together they describe a student. This is our "thing" for this program. What we do to this thing is take the data that represents it (name and grade) and stick them together in a certain way.

So we have a thing (or "object") in the form of a student, and an action ("method") in the form of getting our formatted string. We need a way to describe a student object, and the action that it can perform on itself.

In Java (and many other languages) we call this a "class". The Student class now has attributes called name and grade. These we say are private to the class. That is, only a student can know its own name and grade. It can elect to share that information with others, but they cannot access it without permission.

code:
class Exercise {
   class Student {
      private String name;
      private int grade;
   }
}


Ok, so that's all well and good, but this doesn't do much of anything at all, and nothing useful as far as we're concerned.

We can, however, create a new student that will have a name and a grade. Of course, since we haven't provided any information as to what those are, the student object will be meaningless. To provide some initial information, we need a special method called a "constructor".

The constructor will take as input an initial name, and an initial grade, and what makes it special is that it doesn't return anything. Not even "void". Of course, the constructor is "public", so that anyone can create a new student.

Inside the constructor, we'll set the student's name and grade.

A note on Java, specifically: the constructor method always has the same name as the class.

code:
class Exercise {
   class Student {
      private String name;
      private int grade;
     
      public Student(String initialName, int initialGrade) {
         name = initialName;
         grade = initialGrade;
      }
   }
}


So now we can create a new Student in our "main" method.

code:
class Exercise {
   class Student {
      private String name;
      private int grade;
     
      public Student(String initialName, int initialGrade) {
         name = initialName;
         grade = initialGrade;
      }
   }
   
   public static void main(String[] args) {
      Student johnDoe = new Student("John Doe", 89);
   }
}


Again, we can't really do anything with this, so we have to add a public method to get our specially formatted string, as detailed in the getFormattedString method. In the case of the Student class, we'll use the method name toString. This is the method that is, by convention, used when another class is trying to figure out what an object looks like as a string. For instance, System.out.println.

code:
class Exercise {
   class Student {
      private String name;
      private int grade;
     
      public Student(String initialName, int initialGrade) {
         name = initialName;
         grade = initialGrade;
      }
     
      public String toString() {
         int nameLen = name.length();
         int gradeLen;
        
         if (grade < 10)
            gradeLen = 1;
         else if (grade < 100)
            gradeLen = 2;
         else
            gradeLen = 3;
        
         int numOfDots = 30 - nameLen - gradeLen;
        
         String dots = "";
        
         for (int counter = 1; counter <= numOfDots; counter++)
            dots = dots + "*";
        
         String finalResult = name + dots + grade;
        
         return finalResult;
      }
   }
   
   public static void main(String[] args) {
      Student johnDoe = new Student("John Doe", 89);
      System.out.println(johnDoe);
   }
}

Author:  grasshopper [ Mon Apr 05, 2004 10:29 pm ]
Post subject: 

ooh my gosh wtd.. you just summarized wht my student teacher has been tryin to teach us for like two weeks.. i understand it now!.. you guys are SOOO cool!
but i`m taught to put everything in the main.. that`s how my teacher has been teaching us.. that`s stupid if were going to learn to do it the right way later (in university maybe..(the way you guys are)..

Hacker Dan i`m using BlueJ to run the programs.. and its a ICS3M1 course..

the programs that i`ve been asking for assistant on are not what is needed for the course assignments but similar to help me out a little more.. and not actually get the code for the program (as i should be able to program myself) ..reasons why i find it harder is i guess because i advanced a grade in computer science..and my teacher (student teacher actually.that`s been teaching right now.. has an accent so it`s very hard to understand)..
In Newmarket near Toronto (noo idea where you`re from so incase you don`t know)... in Ontario of course)

Author:  Dan [ Tue Apr 06, 2004 3:55 pm ]
Post subject: 

ah i see, i am doing the grade 12 level of compsci, alougth i fished the noraml cruimale stuff along time ago and am working on amsents from a book they uses at 1st year U of W and some of there permade methods are simmer to the BlueJ ones i gusse.

ya i can be hard to lrean compsci from a teacher that is unschure of them there self. alougth i chage schools this year so i fainly have a compsci teacher who knows what OOP even means Razz

Author:  wtd [ Tue Apr 06, 2004 9:36 pm ]
Post subject: 

Glad I could help. Does this explanation shed any light on my proposed solution for your previous question about inputting ten grades and then finding the max, min, and average?

In the event it doesn't, and because I'm sitting here bored while I wait the requisite 30 minutes before swimming after eating, an analysis that should make it make sense.

Analysis

The problem involves inputting ten grades and finding the minimum grade, the maximum grade, and the average grade. Object-oriented design focuses on the data being manipulated. In this case, that data is 10 grades. We'll assume they're integer values for now. We can represent this as an array of ints in Java. So our class will be GradeCollection (I'm rethinking my original code a bit). These should be hidden within the object and not directly visble from the outside, so we declare the array private.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
   }
}


Ok, that doesn't do a thing. We need a constructor which sets up the initial state of our GradeCollection object. This constructor will need to know how many grades we want to be able to collect, since we're going to make this one flexible. Oh yeah, and we should probably make sure all of those grades are initialized to some default value we'll feed to the constructor.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }
   }
}


Now we can create a new GradeCollection object, but it can't really do anything. We need to give it actions ("methods"). Firstly we'll probably want a way for people looking at this thing from the outside to figure out how many grades it can store. Since the array is private, though, we can't directly see it from outside of the black box that is our object.


code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int length() {
         return grades.length;
      }
   }
}


Next we'll want a method which finds the minimum value in the array and shows it to us.


code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int length() {
         return grades.length;
      }

      public int minGrade() {
         int min = grades[0];
         for (int i = 1; i < length(); i++)
            if (min > grades[i])
               min = grades[i];
         return min;
      }
   }
}


Now, I'll want another method, using almost exactly the same algorithm which finds the maximum grade.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int numberOfGrades() {
         return grades.length;
      }

      public int minGrade() {
         int min = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (min > grades[i])
               min = grades[i];
         return min;
      }

      public int maxGrade() {
         int max = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (max < grades[i])
               max = grades[i];
         return max;
      }
   }
}


Now, I need to find the average grade. Really, this is two issues. First I need to find the sum of all of the grades. This doesn't really need to be visible from outside, though, so let's make it private. The second part is to divide that number by the number of grades in the collection. For the greatest accuracy, let's make the average a floating point number.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int length() {
         return grades.length;
      }

      public int minGrade() {
         int min = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (min > grades[i])
               min = grades[i];
         return min;
      }

      public int maxGrade() {
         int max = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (max < grades[i])
               max = grades[i];
         return max;
      }

      private int sumOfGrades() {
         int sum = 0;
         for (int i = 1; i < numberOfGrades(); i++)
            sum  = sum + grades[i];
         return sum;
      }

      public double averageGrade() {
         return ((double)sumOfGrades()) / numberOfGrades();
      }
   }
}


Oh yeah, and we'll need a way to add a grade at a particular location, since our array of grades isn't accessible from outside.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int length() {
         return grades.length;
      }

      public int minGrade() {
         int min = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (min > grades[i])
               min = grades[i];
         return min;
      }

      public int maxGrade() {
         int max = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (max < grades[i])
               max = grades[i];
         return max;
      }

      private int sumOfGrades() {
         int sum = 0;
         for (int i = 1; i < numberOfGrades(); i++)
            sum  = sum + grades[i];
         return sum;
      }

      public double averageGrade() {
         return ((double)sumOfGrades()) / numberOfGrades();
      }

      public void addGrade(int position, int grade) {
         grades[position] = grade;
      }
   }
}


Now we have everything necessary to create a main routine.

code:
class Exercise {
   public class GradeCollection {
      private int [] grades;
     
      public GradeCollection(int desiredLength, int defaultGrade) {
         grades = new int[desiredLength];
         for (int i = 0; i < desiredLength; i++)
            grades[i] = defaultGrade;
      }

      public int length() {
         return grades.length;
      }

      public int minGrade() {
         int min = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (min > grades[i])
               min = grades[i];
         return min;
      }

      public int maxGrade() {
         int max = grades[0];
         for (int i = 1; i < numberOfGrades(); i++)
            if (max < grades[i])
               max = grades[i];
         return max;
      }

      private int sumOfGrades() {
         int sum = 0;
         for (int i = 1; i < numberOfGrades(); i++)
            sum  = sum + grades[i];
         return sum;
      }

      public double averageGrade() {
         return ((double)sumOfGrades()) / numberOfGrades();
      }
   }

   public static void main(String[] args) {
      BufferedReader keyboard = new BufferedReader(
         new InputStreamReader(System.in));

      GradeCollection grades = new GradeCollection(10, 0);

      for (int i = 0; i < grades.numberOfGrades(); i++) {
         System.out.print("Please input a grade: ");
         int inputGrade = Integer.parseInt(keyboard.readLine());
         grades.addGrade(inputGrade, i);
      }

      System.out.println("Max Grade: " + grades.maxGrade());
      System.out.println("Min Grade: " + grades.minGrade());
      System.out.println("Avg Grade: " + grades.averageGrade());
   }
}

Author:  grasshopper [ Mon Apr 19, 2004 8:04 pm ]
Post subject: 

wtd wrote:
Yes. Teachers aren't always right. Wink

code:
class Exercise {
   public static void printStuff() {
     // code here
   }

   public static void main(String[] args) {
      printStuff();
   }
}


heey... thanks sooo much.. our teacher FINALLY showed us how.. well actually she didn`t she gave us an assignment and told us we had to call them.. so i used that code you gave me.. great help!.. i know this is an old reply.. not sure you`ll even get this.. but thanks SOO mcuh Smile


: