Explaination of simple code?!?!?

hi, im new to java & to this forum.
im a java noob!!!
I was wonder if someone could explain to me
how this code prints out 120 for "r"?
(step by step)
thx java genius's
int [] x;
int r;
int i;
/* 1 */ x = new int[] {2, 3, 4, 5, 6};
/* 2 */ r = 1;
/* 3 */ i = x.length-1;
/* 4 */ while ( i > 0 )
/* 5 */ r = r * x;
/* 6 */ if (r > 100)
/* 7 */ i = i - 1;
else
/* 8 */; // do nothing
/* 9 */ i = i - 1;
/* 10 */ System.out.println( r );                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

120 = 4 * 5 * 6
when > 100 it skip a value and ignores the first value so it stops.

Similar Messages

  • Need Explaination of simple matrix code?!?!?! Thx

    Can someone plz explain this simple code to me!?!? im a noob.
    I know that this code cycles through all the rows & columns of the given
    matrix, but i get completely lost at this part:
    s[row][col] = m[row + theRow][col + theCol] ;
    Regards,
    Slvr99
    this code takes a matrix of integers M, and a
    row and column index, and returns a new matrix that is the lower
    right sub-matrix of M formed from that position. The header
    of the method is as follows:
    public static int[][] submatrix( int[][] m, int theRow, int theCol )
    int[][] s; // RESULT: the submatrix of matrix m
    int sRows; // INTERMEDIATE : number of rows in s
    int sCols; // INTERMEDIATE : number of columns in s
    int row; // INTERMEDIATE: index for row position in s
    int col; // INTERMEDIATE: index for column position in s
    sRows = m.length - theRow;
    sCols = m[0].length - theCol;
    s = new int[sRows][sCols];
    for ( row = 0; row < sRows; row = row + 1 )
    for ( col = 0; col < sCols; col = col + 1 )
    s[row][col] = m[row + theRow][col + theCol] ;
    return s;
    }

    It copies all the values as if [theRow, theCol] were one corner of the origin of matrix.
    I suggest you try running this in a debugger and then you can see what it does line by line.

  • What's wrong with this simple code?

    What's wrong with this simple code? Complier points out that
    1. a '{' is expected at line6;
    2. Statement expected at the line which PI is declared;
    3. Type expected at "System.out.println("Demostrating PI");"
    However, I can't figure out them. Please help. Thanks.
    Here is the code:
    import java.util.*;
    public class DebugTwo3
    // This class demonstrates some math methods
    public static void main(String args[])
              public static final double PI = 3.14159;
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);

    Change your code to this:
    import java.util.*;
    public class DebugTwo3
         public static final double PI = 3.14159;
         public static void main(String args[])
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);
    Klint

  • What is a redo log file? can anyone explain in simple terms

    I am confused between redo log file and physical datafile can anyone explain in simple terms
    Thank u
    Regards,
    Vijay

    See Overview of Physical Database Structures

  • Convert simple code from as2 to as3

    Hello, i am looking for some help here for something simple (i think)
    var txt:String = link1;
    btn.onRelease = function():Void {
    if( sample_id )
    getURL("http://www.website.com/registration?partner_id=" + sample_id + "sampleURLCode", "_blank");
    else
    getURL("http://www.website.com/registration?sampleURLCode", "_blank");
    Is there a way to make this simple code into AS3?

    Hi, Apparantly that's because the 'link1' and 'sample_id' variables are not within the scope of the code you posted above, Perhaps you have defined them outside on a different frame or class. You can either define them with the same code like:
    var sample_id:Number=1234;  //Use your own variable type and value here
    var link1:String = "your string or link URL here";
    var txt:String = link1;
    btn.addEventListener(MouseEvent.CLICK, gotoURL);
    function gotoURL(e:MouseEvent)
    if( sample_id )
          navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
    else
          navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
    Or you can put a direct reference to your existing variable like (If your variables are defined on root/frame 1) :
    var link1:String = "your string or link URL here";
    var txt:String = MovieClip(this.root).link1;
    btn.addEventListener(MouseEvent.CLICK, gotoURL);
    function gotoURL(e:MouseEvent)
    if( MovieClip(this.root).sample_id )
          navigateToURL(new URLRequest("http://www.website.com/registration?sample_id=" + sample_id + "sampleURLCode"),"_blank");
    else
          navigateToURL(new URLRequest("http://www.website.com/registration?sampleURLCode"),"_blank");
    try that, or you can share your .fla !
    cheers

  • Simple code to send ALV display as XLS attachment  to SAP inbox

    Hi All,
    Simple code to send ALV display as XLS attachment  to SAP inbox.
    Also i need to send only 200 records per attachement. So in this case i need send multiple attachment per mail
    Thanks,
    Lokesh

    The following code is used to send the internal table which u pass fo  the ALV display to be send as excel sheet attachment
    Internal table is it_attach[]
    ld_email               = po_email.
      ld_mtitle              = 'Email From Z377_EMAIL_XLS'.
      ld_format              = 'XLS'.
      ld_attdescription      = 'filename'.
      ld_attfilename         = 'Allot'.
      ld_sender_address      = ' '.
      ld_sender_address_type = ' '.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
      ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE li_content LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
      commit_work                = 'X'
    *IMPORTING
    *sent_to_all                = w_sent_all
      TABLES
      packing_list               = t_packing_list
      contents_bin               = t_attachment
      contents_txt               = li_content
      receivers                  = t_receivers
      EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.

  • Jmf simple code

    Hi all,
    this is my simple code that plays a video from a specifed location.
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package javaapplication1;
    * @author rohan
    import com.sun.media.util.ContentType;
    import javax.media.*;
    import javax.media.Manager;
    import java.io.*;
    import java.net.URL;
    import javax.media.bean.playerbean.MediaPlayer;
    import java.awt.*;
    import java.net.ProtocolException;
    import javax.swing.*;
    public class Main extends JFrame{
    * @param args the command line arguments
    public Main()
    try
    Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
    Container cont=getContentPane();
    cont.setLayout(new FlowLayout());
    String myUrl=new String("C:\\Users\\rohan\\Softwares\\Jmf and jain sip\\Fig21_06_07\\bailey.mpg");
    System.out.println("myUrl====="+myUrl);
    MediaLocator myurls =new MediaLocator(myUrl);
    Player myplayer=Manager.createRealizedPlayer(myurls);
    System.out.println("Rohan");
    Component video = myplayer.getVisualComponent();
    cont.add(video);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    myplayer.start();
    catch(Exception e)
    System.out.println("Exception====="+e);
    public static void main(String[] args) {
    // TODO code application logic here
    // JFrame fr=new JFrame("hello");
    Main obj=new Main();
    obj.setBounds(300, 300 , 300, 300);
    obj.setVisible(true);
    Problem here is i get this exception
    "Exception=====javax.media.NoPlayerException: Cannot find a Player for :C:\Users\rohan\Softwares\Jmf and jain sip\Fig21_06_07\bailey.mpg
    Can u plz tel me where do i make changes ,so that i can run this simple app. Plz help me...so that i can go further(plz this is my first jmf app.)
    thanks.

    Change your file path like +"file:/C:/delta.mpg"+.
    Hope this will help you to fix your issue.
    Cheers,
    ARIF

  • Anyone have Simple Code to Play an .Flv file on a Website?

    Hi,
    Can someone please tell me how to make a web page play a .flv file. 
    Simple, basic code would do.
    I have an .flv file uploaded on my website.
    How do I get the Flash Player to play the file when someone visits the page?
    Again, all I'm looking for is simple code.
    Thanks,
    Joe

    add an flvplayback component to your swf.  give it an instance name (say flv).  then use:
    flv.contentPath="yourflv.flv";   // for as2
    flv.source="yourflv.flv";  // for as3

  • Ask for help( simple code but wired error )!

    The post I sent just now has some mistakes. This post is correct. My simple code is as follows:
    import java.io.*;
    import java.net.*;
    public class count {
    float dclient = (float)3.333;
    float dlan = (float)0.01884;
    float drouter = (float)0.00115;
    float doutlink = (float)0.04185;
    float dinternet = (float)1.2615;
    float dinlink = (float)3.18129;
    float client1 = 0;
    float lan1 = 0;
    float router1 = 0;
    float outlink1 = 0;
    float internet1 = 0;
    float inlink1 = 0;
    float client2 = 0;
    float lan2 = 0;
    float router2 = 0;
    float outlink2 = 0;
    float internet2 = 0;
    float inlink2 = 0;
    float x = 0;
    float z = (float)3.333;
    public static void main(String[] args) {
    for (int n=1; n<16; ++n)
    client1 = dclient;
    lan1 = dlan * (1+lan2);
    router1 = drouter;
    outlink1 = doutlink * (1+outlink2);
    internet1 = dinternet;
    inlink1 = dinlink * (1+inlink2);
    x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
    client2 = x * client1;
    lan2 = x * lan1;
    rounter2 = x * rounter1;
    outlink2 = x * outlink1;
    internet2 = x * internet1;
    inlink2 = x * inlink1;
    System.out.println(client1 + " " +
    lan1 + " " +
    rounter1 + " " +
    outlink1 + " " +
    internet1+ " " +
    inlink1+ " **** " +
    x + " **** " +
    client2 + " " +
    lan2 + " " +
    rounter2 + " " +
    outlink2 + " " +
    internet2+ " " +
    inlink2 + " ********************end of n = " + n + "************************"
    The compiling error is:
    count.java:43: Can't make a static reference to nonstatic variable dclient in class count.
    client1 = dclient;
    ^
    1 error
    What is wrong with it? Many thanks!

    import java.io.*;
    import java.net.*;
    public class count
         public static float dclient = (float)3.333;
         public static float dlan = (float)0.01884;
         public static float drouter = (float)0.00115;
         public static float doutlink = (float)0.04185;
         public static float dinternet = (float)1.2615;
         public static float dinlink = (float)3.18129;
         public static float client1 = 0;
         public static float lan1 = 0;
         public static float router1 = 0;
         public static float outlink1 = 0;
         public static float internet1 = 0;
         public static float inlink1 = 0;
         public static float client2 = 0;
         public static float lan2 = 0;
         public static float router2 = 0;
         public static float outlink2 = 0;
         public static float internet2 = 0;
         public static float inlink2 = 0;
         public static float x = 0;
         public static float z = (float)3.333;
         public static void main(String[] args)
              for (int n=1; n<16; ++n)
                   client1 = dclient;
                   lan1 = dlan * (1+lan2);
                   router1 = drouter;
                   outlink1 = doutlink * (1+outlink2);
                   internet1 = dinternet;
                   inlink1 = dinlink * (1+inlink2);
                   x = n / (z + client1 + lan1 + router1 + outlink1 + internet1 + inlink1);
                   client2 = x * client1;
                   lan2 = x * lan1;
                   router2 = x * router1;
                   outlink2 = x * outlink1;
                   internet2 = x * internet1;
                   inlink2 = x * inlink1;
                   System.out.println(client1 + " " +     lan1 + " " router1 " " outlink1 " " internet1 " " inlink1 " **** " +     x + " **** " +
                   client2 + " " +
                   lan2 + " " +
                   router2 + " " +
                   outlink2 + " " +
                   internet2+ " " +
                   inlink2 + " ********************end of n = " + n + "************************"

  • Data Binding: Simple code does not work.

    hi... the following simple code is used to display the ename field for a record selected in scott.emp on the console. the code is placed in an event handler. it is as follows:
    DCBindingContainer bindings = ctx.getBindingContainer();
    DCControlBinding binding = bindings.findCtrlBinding("ename");
    String Name = (binding != null) ? binding.toString() : "";
    System.out.println(Name);
    is the code above correct????
    if so, why it does not work???
    thanks for every help in advance & best regards.

    Hi,
    please check the UIModel.xml file for the page if the binding name is "name". The code you have is the same code we published in our QBE workshop and it works there. The only difference is the name of the control binding. So please check if the binding name exists. (e.g. it could be ename1 instead of ename)
    Frank

  • Can anyone explain in simple terms how to set up icloud when I have 2 identities?

    I use my mac.com id for my calendar and contacts, but have a different ID for store purchases and everything else.  I would like to set up my iCloud with a single ID, but I don't want to lose all my historical calendar and contact data, so I need my iCloud tpo import the data from the Mobile.Me 'mac.com' account.
    Everything I have read is confusing....can anyone explain in simple terms how I sert the iCloud up?  I run a Macbook, a Windows 7 PC and an iphone, and I need them all to syns together.
    Any help appreciated.
    CliffWragg

    Welcome to the Apple Community.
    You can drag all your contacts (all at once) and each calendar from address book and iCal to your desktop as a back up/copy. Once you have set up iCloud using the ID for your apps, books and tunes etc, you can add the contacts and calendars to the new account by clicking on the desktop files, iCloud will sync them to your other devices.

  • What's the simple code for this?

    Hello, I know it is a very simple code but what is the code if I want to have different properties for headings and such in different id's. For example I want ID "sidebar"'s headings to be aligned in the center but I want ID "main-body"'s headings to be aligned to the left. How would I go about doing that?
    Thanks!

    CSS:
    body {
    text-align:left;
    #sidebar h1,
    #sidebar h2,
    #sidebar h3,
    #sidebar h4 {text-align:center}
    /**re-usable classes**/
    .center {text-align:center}
    .right {text-align:right}
    HTML:
    <div id="main_body">
         <h1>This is left aligned by default</h1>
         <h2 class="right">This is right aligned by virtue of the class .right.</h2>
    </div>
    Nancy O.

  • Can someone explain me this code?

    Hi... pls explain me this code if possible.
    try {
    wdContext.nodeStateList().bind( (Z_Hress_P0006_State_Input)model.createModelObject(Z_Hress_P0006_State_Input.class));
    wdContext.currentStateListElement().setI_Withemptyline(true);
    wdContext.currentStateListElement().setI_Countrykey(
                        wdContext.currentCountryRecordsElement().getLand());
                   wdContext.currentStateListElement().modelObject().execute();

    Pankak,
    wdDoInit is a method in Web Dynpro controllers that ie executed when controller code is executed first time (initialized) its never run again in the lifespan of that controller (view controller, component controller, custom controller).
    You can get some more introductory material about Web Dynpro here
    https://www.sdn.sap.com/irj/sdn/developerareas/webdynpro?rid=/webcontent/uuid/063bc942-0a01-0010-e7ae-d138e97acb5a [original link is broken]
    Also I would suggest you to buy the Inside Web Dynpro book.
    http://www.sappressbooks.com/product.cfm?account=&product=H983
    This book will help to make your web dynpro concepts solid. I am assuming you know java.
    Regarding the point, i don't have much idea how to give the points, I assume when you close the question you can assign the points.
    Regards,
    Anand

  • XML simple code help

    Hello Everyone, I am learning XML and I'm trying to make a simple code that will display three different messages on a separate line. I already have the code but there is something that does not let it work. Please if somebody can take a quick look at the code and tell me what should I do in order to get it working. Thanks in advance
    This is my simplerequestdata.xml
    {<root>
    <message1>This</message1>
    <message2>Technology</message2>
    <message3>Is confusing</message3>
    </root>}
    This is my xmlrequest.html code
    {<html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    var req=null;
    function xhr(){
    try
    { // Firefox, Opera 8.0+, Safari
    req=new XMLHttpRequest();
    catch (e)
    // Internet Explorer
    try
    req=new ActiveXObject("Msxml2.XMLHTTP");
    catch (e)
    req=new ActiveXObject("Microsoft.XMLHTTP");
    return req;
    function getData(){
    req = new xhr();
    req.open("get","simpleRequestData.xml");
    req.send(null);
    if(req.readyState==4){
    if(req.status==200){
    var doc = req.responseXML;
    var msgNodes = doc.documentElement.getElementsByTagName('message');
    var msgDiv = document.getElementById("message");
    var msg = document.createElement("message");
    msg.innerHTML = msgNodes[0].firstChild.nodeValue + "<br />" + msgNodes[1].firstChild.nodeValue + '
    ' + msgNodes[2].firstChild.nodeValue;
    msgDiv.innerHTML = '';
    msgDiv.appendChild(msg);
    </script>
    <style>
    #message{color:red;}
    message{display:block;color:green;}
    </style>
    </head>
    <body>
    <form>
    <input type="button" onclick="getData()" value="Get Message"/>
    <div id="message">Message Goes Here</div>
    </form>
    </body>
    </html>
    }

    That looks like Javascript to me. This forum is about Java and XML, not Javascript and XML. However the error is pretty obvious:
    var msgNodes = doc.documentElement.getElementsByTagName('message');You don't have any elements named "message" in that XML document. You have an element named "message1" and an element named "message2" and an element named "message3", but no "message" elements. So you get a list of zero elements there. You need to rewrite your DOM-handling code to reflect the actual input.

  • How to sort a list of strings, without methods and stuff just simple code?

    Hi
    How to sort a list of strings, without methods and stuff just simple code?
    Thanks in adavance!!

    Without methods? How are you going to all the sort code? What is the point of code?
    Collections.sort(List) will sort strings or anything that implements the Comparable interface, or you can use the sort method that takes a Comparator implemenation.
    If you want "just code", you could either get the Collections class souce and follow it to the code. But otherwise, there isn't one set of code. There are various sorting algorithms with advantages and disadvantages. Maybe you'd be better off searching for sorting algorithms and if you understand them, it should be simple to write Java implementations of them.

Maybe you are looking for

  • PDF Printer missing

    Acrobat Pro X, Vista Ultimate (32 bit).  PDF printer is nowhere to be found.  Tried reinstalling. I'm honestly not sure it was there when I installed it the first time.  But it is there on my Win 7 machine. Thoughts?  Fixes? Thanks. - Martin

  • Help with Installing Lightbox 2 in Adobe golive cs2

    Iam having some difficulty installing lightbox 2 for a gallery that I want to creat on my website, Ive downloaded the latest version. Do I just drop the whole folder (lightbox 2 into my site window? then add the code for javascript in the header wind

  • Logging of SOAP messages at server side, Axis 1.2, NO SoapMonitor / TCPMon.

    Hello, I�m looking for a way to log all SOAP communication at a Axis Server. I want to log the messages into my logdatabase or to files at least. I am not interrested af SOAPMonitor or TCPMonitor, those are good tools but not for my purposes. Anyone

  • MobileMe Gallery movies dont show on iPhone 3g

    I have about 6 movies on my gallery page but only one of them shows up when I navigate there on my iPhone. Is there a size cap for movies that will show from the MobileMe gallery on an iPhone. Any ideas why the others wont show?

  • CORBA client reconnection: InvalidDomain

    I'm developing a CORBA-client for WLE 5.1. In short, the problem is: I can't restore a connection after a COMM_FAILURE. When trying to create a Tobj_Bootstrap object again I get com.beasys.Tobj.InvalidDomain: Can't connect to the domain (//my.domain: