Thread: [Java Tutorial]Arrays, Strings, Loops

Results 1 to 7 of 7
  1. #1 [Java Tutorial]Arrays, Strings, Loops 
    Registered Member

    Join Date
    Dec 2011
    Age
    29
    Posts
    794
    Thanks given
    92
    Thanks received
    84
    Rep Power
    250
    You're welcome to my first ever java tutorial

    What you're learning: Arrays, Strings, making a for loop.
    Difficulty: Easiest thing in java

    Now let's begin from learning about loops

    What is a loop?
    Ans.
    A loop is a method-like structure in java which executes more than one time, as demanded by the author until the boolean expression doesn't come true.

    What are the advantages of using a loop?
    Ans.
    There are many advantages of a loop like
    -You don't have to type the sequence again and again, just set it and your loop will execute the same thing again and again.

    How many types of loop are there?
    Ans.
    There are 3 types of loop, eg. while, for,etc.

    Which one is the easiest and which one are you teaching?
    Ans.
    In my opinion, a for loop is the easiest one and it's exactly the one I'm teaching.

    A for loop is a loop system which executes until the given condition is not true.

    A syntax of a for loop is
    Code:
     for(Initialization;boolean expression;Update;) {
            //executable part or statements
                }
    Now let's start with a program which will print the same string 4 times
    Code:
        package tutorial;
            
            public class learnForLoop {
    
            public static String myOutput = "Let the foetus hit the floor.";
        //You will find description about Strings in the next part of the tut
                public static void main (String[] args) {
                    for(int i = 0; i <= 4; i++) {
                System.out.println(myOutput);
                    }
                }
            }
    This will print the String "Let the foetus hit the floor" 5 times.

    Code:
    Let the foetus hit the floor.
    Let the foetus hit the floor.
    Let the foetus hit the floor.
    Let the foetus hit the floor.
    Let the foetus hit the floor.

    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Dec 2011
    Age
    29
    Posts
    794
    Thanks given
    92
    Thanks received
    84
    Rep Power
    250
    Now let's learn about Strings.

    What is a String?
    Ans.
    A String is a sequence of multiple characters.

    I don't understand, can you please give me an example?
    Ans.
    Well the word 'Extra' consists of 5 characters and is a String in Java programming.

    Oh, how do I use a String?
    Ans.
    The initialization of a String is similar to that of an integer.

    For instance,
    Code:
            String name = "Hunter";
    Multiple Strings can be bound together to give a combined output, like
    Code:
            public static int age = 20;
        public static String name = "Thee Rash";
            public static void main (String[] args) {
                System.out.println("Our moderator "+name + " is "+ age+ " years old.");
        }
    This will print the following output:-
    Code:
    Our moderator Thee Rash is 20 years old.
    Now let's head to Arrays

    What is an Array?
    Ans.
    An array is a sequence of information of the same data type.

    Usage of an Array:

    Code:
         public static int[] fag = {1,2,3};
        public static String lastWord = "Go!";
    
            public static void printOutput() {
                        System.out.println("Okay ");
                for(int h = 0; h < fag.length; h++) {
                            System.out.println(fag[h]);
                        }
                            System.out.println(lastWord);
            }
    Output:-

    Code:
    Okay 
    1
    2
    3
    Go!

    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Dec 2011
    Age
    29
    Posts
    794
    Thanks given
    92
    Thanks received
    84
    Rep Power
    250
    Let's create a program which tells us about the itemIds of Spirit shields

    Code:
    package random;
    
    /**
     *
     * @author AYUSHARYA
     */
    public class Random {
    
        /*
         * Start of variable declarement
         */
    
        public static String[] Names = {"Divine Spirit Shield","Elysian Spirit Shield","Spectral Spirit Shield","Arcane Spirit Shield","Blessed Spirit Shield","Spirit Shield"};
        public static int[] itemIDS = {13740,13742,13744,13738,13736,13734};
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
                    for(int i = 0; i < Names.length; i++) {
            System.out.println("The item id of "+Names[i] + " is "+ itemIDS[i]+ ".");
                    }
        }
    }
    This will give us the following output
    Code:
    The item id of Divine Spirit Shield is 13740.
    The item id of Elysian Spirit Shield is 13742.
    The item id of Spectral Spirit Shield is 13744.
    The item id of Arcane Spirit Shield is 13738.
    The item id of Blessed Spirit Shield is 13736.
    The item id of Spirit Shield is 13734.
    Hope you enjoyed learning.

    Credits:-
    FortNightAtmo/Ayush Arya/Me

    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Mar 2013
    Posts
    3,036
    Thanks given
    82
    Thanks received
    375
    Rep Power
    0
    why.
    Reply With Quote  
     

  5. #5  
    Renown Programmer

    Join Date
    Dec 2010
    Posts
    2,876
    Thanks given
    508
    Thanks received
    1,898
    Rep Power
    5000
    get off this forum
    never talk to me or my wife's son ever again
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Dec 2012
    Age
    27
    Posts
    97
    Thanks given
    6
    Thanks received
    11
    Rep Power
    56
    Didnt really learn much from this but thanks for contributing
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    May 2014
    Posts
    85
    Thanks given
    30
    Thanks received
    14
    Rep Power
    20
    That "bounding strings together" is called concatenation. You also never went over foreach loops (enhances for loops), nor do you show a basic array, which is very important

    Code:
    int[] array = new int[10];
    The array you explained MUST have values when initialized. The amount of values inside at initialization determines the array size. If you dont want to initialize with items inside already, its critical to understand using the 'new' keyword to create a new array object.

    At least you tried, props for that. Looks like you covered some basics, and im sure it took you some time. Try to fix it up though
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Basic Java - Arrays (Strings)
    By Xynth in forum Tutorials
    Replies: 8
    Last Post: 05-04-2010, 05:23 AM
  2. JAVA tutorials
    By Steel in forum Requests
    Replies: 2
    Last Post: 11-29-2008, 08:59 PM
  3. java tutorials
    By badboy ownz in forum RS 503+ Client & Server
    Replies: 9
    Last Post: 08-10-2008, 11:00 PM
  4. [JAVA]Tutorials[/JAVA]
    By Ownage Plz in forum Tutorials
    Replies: 26
    Last Post: 11-14-2007, 12:00 AM
  5. Java, from the bean up [Java tutorial]
    By Lem0ns in forum Tutorials
    Replies: 0
    Last Post: 08-13-2007, 12:30 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •