Can you help me with this code

hi am new to java so please bare with me , so in this code as you can see i comment some lines of code the one i comment works when i compile it , but why the one with fields does not ? can you please explain this to me
public class Demo3
               public static int a = 5;
               public static int b = 6;
               public static int c = a+b;
               public static int d = b-a;
               a*=5;
     public static void main (String [] args)
          /*int a = 5;
          int b = 6;
          int c = a+b;
          int d = b-a;
          a*=5;
          System.out.println (a);
          System.out.println (b);
          System.out.println (c);
          System.out.println (d);
}

>
public class Demo3
               public static int a = 5;
               public static int b = 6;
               public static int c = a+b;
               public static int d = b-a;
               a*=5;This is not possible. write this statement in a function.
or
in a static block like
static  {
      a*=5;
}>
     public static void main (String [] args)
          /*int a = 5;
          int b = 6;
          int c = a+b;
          int d = b-a;
          a*=5;
          System.out.println (a);
          System.out.println (b);
          System.out.println (c);
          System.out.println (d);

Similar Messages

  • Can somebody help me with this code?

    Can anyone help me with this code? My problem is that i can't
    seem to position this form, i want to be able to center it
    vertically & horizontally in a div either using CSS or any
    other means.
    <div id="searchbar"><!--Search Bar -->
    <div id="searchcart">
    <div class="serchcartcont">
    <form action='
    http://www.romancart.com/search.asp'
    name="engine" target=searchwin id="engine">
    <input type=hidden value=????? name=storeid>
    <input type=text value='' name=searchterm>
    <input type=submit value='Go'> </form>
    </div>
    </div>
    <div class="searchcont">Search For
    Products:</div>
    </div><!-- End Search Bar -->
    Pleasssssseeeeeeee Help
    Thanks

    Hi,
    Your form is defined in a div named "serchcartcont", you can
    use attributes like position and align of the div to do what you
    want to do. But there are two more dives above this dive, you will
    have define the height width of these before you can center align
    the inner most div. If you are not defining the height & width
    then by default it decide it automatically to just fit the content
    in it.
    Hope this helps.
    Maneet
    LeXolution IT Services
    Web Development
    Company

  • HT204146 Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Hi
    Has iTunes completed its scan of your iTunes library on your computer Subscribing to iTunes from an iOS device.
    Jim

  • I am using Dreamweaver CS4  and can no longer connect to Device Central - Can you help me with this?

    I am using Dreamweaver CS4  and can no longer connect to Device Central - Can you help me with this?

    Device Central was discontinued April 23, 2012.
    http://www.adobe.com/products/devicecentral.html
    And replaced with Adobe Edge Inspect CC (for Cloud subscribers)
    http://html.adobe.com/edge/inspect/
    Nancy O.

  • I run Windows 7 Home Premium on an HP Pavilion dv6. I cannot install iTunes or QuickTime. Can you help me with this?

    I run Windows 7 Home Premium on an HP Pavilion dv6. I cannot install iTunes or QuickTime. Can you help me with this?

    Hello raadabdaun,
    Thanks for the question, and welcome to Apple Support Communities.
    I understand you are having issues installing iTunes for Windows. The following article provides the most relevant information and troubleshooting steps:
    Trouble installing iTunes or QuickTime for Windows
    http://support.apple.com/kb/HT1926
    Thanks,
    Matt M.

  • What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..

    What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..?
    I try also my old icloud user but its not recognizing the accoun...

    What will i do..there is a message show, "your device in not more eligible to create a free i cloud acount"..and when i try a new one it ask an account number, but i dont have...can you help me with this issue..?
    I try also my old icloud user but its not recognizing the accoun...

  • HT2801 I understand there is a way to use my Super Drive with my PC.  However, it requires a System OS Disk.  Which I never received.  Can you help me with this?

    I understand there is a way to use my Super Drive with my PC.  However, it requires a System OS Disk.  Which I never received.  Can you help me with this?

    Rick6812 wrote:
      I'm using Windows 8.1. 
    I do not know what you mean by a Windows 8.1.  Please clarify.
    The Apple superdrive is designed to be used with the following Macs.
    It will not work with any other Mac unless you perform this modification;
    http://www.tuaw.com/2012/04/02/use-the-macbook-air-superdrive-with-any-almost-ma c/
    Are you trying to get it to work with a PC? 
    Ciao.

  • I play Zuma Blitz on FB; Ever since I upgraded to Firefox 4 I can't play the game the darn frog pauses before shooting and it's a mess; you know it's what I enjoy doing and it needs to be fixed can you help me with this??? Thanks

    Question
    I play Zuma Blitz on FB; Ever since I upgraded to Firefox 4 I can't play the game the darn frog pauses before shooting and it's a mess; you know it's what I enjoy doing and it needs to be fixed can you help me with this??? I am super frustrated ith the situationThanks

    Upgrading to firefox 5 and updating my plug-ins helped a bit. Frog is less 'sticky' now, but it's not solved the problem. Java needs to be up to speed or the frog goes into stasis....

  • We live in motel but my iMac is not connecting with the internet but my cousin has hp laptop that works perfectly fine in my room. So can you help me with this situation?

    We live in motel but my iMac is not connecting with the internet but my cousin has hp laptop that works perfectly fine in my room. So can you help me with this situation?

    Joining an encrypted WEP or WPA Wi-Fi network

  • HT4759 In trying to renew iCloud on my iphone I keep getting the response that the security code of my credit card is incorrect. Can you help me with this?

    I have tried to renew my icloud subscription on my iphone. I have been unsuccessful after several attempts. The last time the reason give was that the security code of my credit card is incorrect. It is the number. Can you help?

    Have you tried checking your payment information details to make sure the CVV (security) code is correct (see http://support.apple.com/kb/HT1918)?

  • Can you help me with this ( vlan,accesslist,management )

    here's the scenario I have two vlan 10 & 20
    I have 2 switch and 1 router
    the target of this setup is that vlan 10 can ping or reach vlan 20 but vlan 20 cannot be reach or ping vlan 10 it is that possible
    Here's the setup
    In SW0
    vlan 10
    name Management
    interface FastEthernet0/1
    switchport access vlan 10
    switchport mode access
    interface FastEthernet0/2
    switchport trunk allowed vlan 10
    switchport mode trunk
    In SW1
    interface FastEthernet0/1
    switchport trunk allowed vlan 20
    switchport mode trunk
    interface FastEthernet0/2
    switchport access vlan 20
    switchport mode access
    interface FastEthernet0/3
    switchport access vlan 20
    switchport mode access
    In Router
    interface FastEthernet0/0.10
    encapsulation dot1Q 10
    ip address 192.168.10.1 255.255.255.0
    ip access-group 1 out
    interface FastEthernet0/0.20
    no ip address
    interface FastEthernet0/1
    no ip address
    duplex auto
    speed auto
    interface FastEthernet0/1.20
    encapsulation dot1Q 20
    ip address 192.168.20.1 255.255.255.0
    ip access-group 1 out
    interface Vlan1
    no ip address
    shutdown
    ip classless
    access-list 1 deny 192.168.20.0 0.0.0.255
    access-list 1 permit 192.168.10.0 0.0.0.255
    access-list 1 deny host 192.168.20.11
    access-list 1 permit host 192.168.10.11
    access-list 1 deny any
    access-list 1 permit any
    Im new so i dont know if my setup is correct ...
    can any1 help me about this,,,
    thanks.

    Hi,
    let's suppose PC0(Vlan 10) wants to communicate with PC1(Vlan 20):
    -traffic enters f0/0.10 with src 10.11 and dst 20.11 and it is forwarded out f0/1.20 where there is an egress ACL
    -this is a standard ACL so it matches on source only and there is a hit for second entry permit 192.168.10.0 0.0.0.255
    -now PC1 replies and traffic enters f0/1.20 and is forwarded out f0/0.10 where there is egress ACL
    -there is a hit on first entry  deny 192.168.20.0 0.0.0.255( packet src is 20.11 and dst 10.11)
    So end result is that Vlan 10 cannot reach Vlan 20.
    I don't think this is what you wanted
    Now of course traffic sourced from any PC in Vlan 20 destined to PC0 is filtered as you wanted because  it is filtered on f0/0.10 outbound as above.
    ACLs are stateless and communication in TCP/IP is bidirectional so the best way to achieve what you want to do if you want to filter more than Pings would be to use CBAC or ZBF or reflexive ACLs
    Regards
    Alain
    Don't forget to rate helpful posts.

  • Can anybody help me with this code?

    I am a beginner to J2ME. The following is a small program I wrote just for test.
    Theoretically, in my opinion, I shall see in the screen a number increase from 1 to 29999 rapidly after execute the code. But instead, it displays nothing but only displays 29999 after several seconds . Can some body point out what's wrong with this code? Thanks.
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Test extends MIDlet{
    int x=1;
    String b="";
    private Display display;
    public Test() {
    display = Display.getDisplay(this);
    public void startApp() {
    MyCanvas mc = new MyCanvas() ;
    display.setCurrent(mc) ;
    while(x<30000){
    b=String.valueOf(x);
    mc.repaint();
    x++;
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    class MyCanvas extends Canvas{
    public void paint(Graphics g){
    g.drawString(b,10,10,0);

    thanks, I have already got the answer. you are right, if repaint in a high speed the screen will show nothing. here is the code for it, thanks the expert of nokia forum.
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    //Counter
    //Need to know when a number has been painted and need to wait a for a fraction of a sec before
    //painting the next number. This wait also allows other events like "Exit" to be processed
    //Use double buffering to avoid flicker
    //Paint in a different thread to keep the UI responsive
    public class MyMIDlet extends MIDlet{
    int x=1;
    String b="";
    private Display display;
    Thread t = null;
    MyCanvas mc = null;
    public MyMIDlet() {
    display = Display.getDisplay(this);
    public void startApp() {
    mc = new MyCanvas();
    t = new Thread(mc) ;
    display.setCurrent(mc) ;
    b=String.valueOf(x);
    t.start();
    public void callbackPaintDone(){
    try{
    //provides the delay between every repaint and also time to react to Exit
    synchronized(this){
    wait(1);
    }catch(Exception e){}
    paintNextNumber();
    private void paintNextNumber(){
    if(x<30000){
    x++;
    b=String.valueOf(x);
    mc.doPaint = true; //signals that next number can be painted
    public void pauseApp() {
    public void destroyApp(boolean unconditional) {
    class MyCanvas extends Canvas implements Runnable{
    Image buf = null;
    Graphics bg = null;
    public boolean doPaint = true;
    public MyCanvas(){
    buf = Image.createImage(getWidth(),getHeight());
    bg = buf.getGraphics();
    public void paint(Graphics g){
    bg.setColor(255,255,255);
    bg.fillRect(0,0,getWidth(),getHeight());
    bg.setColor(0);
    bg.drawString(b,10,10,0);
    g.drawImage(buf,10,10,Graphics.TOP|Graphics.LEFT);
    // Callback for next number to be painted
    MyMIDlet.this.callbackPaintDone();
    public void run(){
    while(true){
    if(doPaint){ //only paints when a number has been painted, and next one is ready to be painted
    doPaint = false;
    repaint();
    serviceRepaints();

  • I've installed Firefox 4 and under the Firefox Menu button on the top-left there is no option to set up Firefox "sync". Can you help me with this?

    I thought I had registered before but had to re-register today. I tried to retrieve my old password using my [email protected] E-Mail address but got no response from Firefox.
    I have an HTC Incredible Android phone and would like to use Firefox as my browser on it, and "sync" its operation to the Firefox application I use on my Apple iMAC. Can you help me?

    Hi from Mozilla Services Operations. We just fixed an issue with the "forgot password" process. If you try to retrieve your old password again, you should receive an email at your account's email address with further instructions.

  • Can someone help me with this code?

    Hi all,
    I have a Flash component that links to a gallery, and I
    understand that I can create buttons to point to multiple
    galleries. (waiting too long for support from the suppliers)
    The User Guide says that I can use the following to create
    the connection:
    myThumbnailer2.loadGallery(24);
    That won't work, and it says that I need to include it in an
    onclipevent. I have no idea what i am doing and I was hoping
    someone could tell me what to script to get the text button I
    created to run this.
    Help would really be appreciated.
    Hugh

    Hi Hugh,
    You are right in that you can link to other galleries using
    the ID number (but, I assume, only TN2Admin (fCMSPro gallery
    document) defined galleries) with the code supplied.
    I think this may help - I'm a newbie with actionscript and I
    know nothing about Flashloaded so I may be way off beam here,
    but....
    First define a variable, this will be used in the 'show'
    (that's show, not load) gallery element of your code:
    var galNum: Number;
    Make as many buttons as required to launch a gallery (you say
    "each button opening one of several galleries" so I assume you want
    1 gallery per button) and give each an instance name.
    You then write the relevant code for each button function
    (assuming once more that the buttons are in the same frame) using
    the instance name (I use a separate layer in the frame to write
    actionscript and try not to attach code directly to objects - which
    then leads me to say yes you can put all the different buttons code
    in one frame)....
    myLoadGalBtn1.onRelease = function () {
    myThumbnailer2.loadGallery(24);
    galNum = 24;
    myLoadGalBtn2.onRelease = function () {
    myThumbnailer2.loadGallery(25);
    galNum = 25;
    notice the buttons have different instance names (the 1 &
    2 at the end - but you can call them what you like).
    Then you can use other code supplied to actually show the
    gallery (using the variable generated in each button click). Some
    code from Flashloaded will be along the lines of:
    myThumbnailer2.showGallery(25);
    so my guess is you can replace the actual number with the
    variable galNum inside the brackets to use the number generated by
    whatever button was pressed, like:
    myThumbnailer2.showGallery(galNum);
    Cheers
    Kol

  • Can you help me with this problem? Please!

    I had just created this program that calculates the amount due from an international phone call. and I was wondering what I can do to get the program to execute when the user inputs let's say 3min and some amount of seconds. The program works when the number of minutes the call lasted is an integer, but it does not when the number of minutes the call lasted is lets say 4min30sec. Is there anyway I can get my program to execute both minutes and seconds? Help is very appreciated.
    Here's the program:
    import java.io.*;
    import java.text.DecimalFormat;
    public class PhoneCallBilling_Lab4
         static BufferedReader keyboard = new
         BufferedReader(new InputStreamReader(System.in));
         //Named constants
    static final double CONNECTION_FEE = 1.99;
    static final double FIRST_THREE_MIN_FEE = 2.00;
    static final double COST_OF_EACH_ADDITIONAL_MIN = 0.45;
         public static void main(String[] args) throws IOException
         //Variable declaration
    int noOfMinCallLasted;
    double amountDue;
    DecimalFormat twoDigits =
    new DecimalFormat("0.00");
    System.out.println("This program computes an international phone call.");
    System.out.print("Enter the number of minutes the call lasted: ");
    noOfMinCallLasted =
    Integer.parseInt(keyboard.readLine());
    System.out.println();
    if (noOfMinCallLasted<= 3)
         amountDue = CONNECTION_FEE +
         FIRST_THREE_MIN_FEE;
    else
    amountDue = CONNECTION_FEE +
    FIRST_THREE_MIN_FEE +
    (noOfMinCallLasted - 3) * COST_OF_EACH_ADDITIONAL_MIN;
    System.out.println("The number of minutes the call lasted was "
              + noOfMinCallLasted);
    System.out.println("Amount due = $"
    + twoDigits.format(amountDue));
    }

    How about converting the minutes to seconds and doing
    your calulations all in seconds?ok. I am going to try that but don't you think that it would be quite cumbersome if I was to have someone actually input information. They would have to go through the entire process of trying to figure out how many minutes is in a second and all of the other problems that may occur. If I didnt have to consider all possibilities when executing this program I could leave it as is. However, I have to. And the problem states that we (as in students) have to get the user to input the number of minutes and seconds and the program has to execute.

Maybe you are looking for

  • Fourth disconnection from FiOS internet service in five days

    I have been with FiOS for at least four years. I had never causing connection problem been very stable and reliable. However, I experienced internet disconnection four times for the last five days while FiOS TV and telephone were still working well.

  • Libraries-MS no longer working

    Under the heading of Libraries-MS (i.e. Documents, Music, Pictures, Videos) I get the message "no longer working - Delete headings, folders will not be affected". Pictures are stored elsewhere, but documents I cannot access/or save new ones. I do not

  • New hard disk not detected on openboot

    hello guys, would like to request help if there are any settings i need to enable for a netra t1 to detect the new hard disks that were added on a dell disk array. the netra t1 is able to detect scsi hds 1-3 but not the 8-11. have checked netra t1 ma

  • Serial Compatibility VI's not working in Labview 7.0

    I recently upgraded from Labview 6.02 to Labview 7.0 and found that my application could no longer open or communicate via a serial port. My application uses and I prefer the old serial compatibility VI's because I had trouble with the VISA serial VI

  • Open Hub in Windows 7

    Hi Has anyone used OpenHub with windows 7 as destination? Mine is creating a large number of trc files but no data. Thanks in advance for your help. Points will be awarded for right answer.