Simple code somthings wrong plz check them:)

code 1:
import java.awt.*;
class Yo {
public static void main (String[] arg) {
String s;
double i;
System.out.print("Translate to euro! Input the swedish money: "); System.out.flush();
s = myIn.readLine();
i = Double.parseDouble(s);
System.out.println(i, "SEK blir" + i*9.15781 + "euro" );
code 2:
class Halt {
public static void main (String[] arg) {
System.out.print("Halt! Who goes there?"); System.out.flush();
String s = myIn.readLine();
System.out.println("You may pass " + s + "!");
I think the errors are similar to eachother.. plz tell me whats wrong with the "myIn" thing:)

why not import Scanner and use that to get user input? all you would have to do is this:
import java.util.Scanner
//blah blah blah
//create the following object before you call it
Scanner myln = new Scanner (System.in);
//ask for user input
double i = myln.nextDouble();
//end output

Similar Messages

  • Simple code, but wrong, please help.

    I wrote the follow code. When I call it in another class but no disaply. What happens? Please help me to correct it. Thanks.
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class tempStr extends JApplet{
    final static Color bg = Color.white;
    final static Color fg = Color.black;
    String str;
    tempStr(String string){
         str=string;
         JFrame f = new JFrame("string draw");
            JApplet applet1 = new tempStr(str);
            f.getContentPane().add("Center", applet1);
            applet1.init();
            f.pack();
           f.setSize(new Dimension(400,400));
            f.show();
        public void init() {
            setBackground(bg);
            setForeground(fg);
    public void paint(Graphics g) {
      Graphics2D g2=(Graphics2D)g;
        g2.drawString(str, 40,160);
      }

    It would be better to move the creation code into some dedicated method:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class tempStr extends JApplet{
        final static Color bg = Color.white;
        final static Color fg = Color.black;
        String str;
        tempStr(String string){
            str=string;
        public void init() {
            setBackground(bg);
            setForeground(fg);
        public void paint(Graphics g) {
            Graphics2D g2=(Graphics2D)g;
            g2.drawString(str, 40,160);
        public static void main(String argv[]) {
            JFrame f = new JFrame("string draw");
            JApplet applet1 = new tempStr(argv[0]);
            f.getContentPane().add("Center", applet1);
            applet1.init();
            f.pack();
            f.setSize(new Dimension(400,400));
            f.show();
    }To lauch the applet from command line:
    java tempStr "Hello world"

  • 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

  • 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

  • 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

  • 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

  • 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.

  • Still having probs running simple code in SE8

    I copied a very simple code into SE8 and compiled it. Please find folowing the code and the output:
    package average2;
        import java.text.DecimalFormat;
        import java.swing.JOptionPane;
    public class Main {
        public Main() {
        public static void main( String args[] )
                int total;          // sum of grades
                int gradeCounter;   // number of grades entered
                int grade;          // grade value
                double average;     // number with decimal point for average
                String gradeString; // grade typed by user
                // initialisation
                total = 0;          // initialise total
                gradeCounter = 0;   // initialise gradeCounter
                // processing phase
                // get first grade from user
                gradeString = JOptionPane.showInputDialogue( "Enter Student Grade or -1 to Quit:" );
                // convert gradeString to int
                grade = Integer.parseInt( gradeString );
                // loop until sentinal value is reached
                while ( grade != -1 ) {
                    total = total + grade;          // add grade to tatal
                gradeCounter = gradeCounter + 1;    // increment counter
                // get next grade from user
                gradeString = JOptionPane.showInputDialogue( "Enter Student Grade or -1 to Quit:" );
                // convert gradeStrin to int
                grade = Integer.parseInt( gradeString );
            }   // end while
                // termination phase
                DecimalFormat twoDigits = new DecimalFormat( "0.00" );
                // if user entered at leat one grade...
                if( gradeCounter != 0 ) {
                    // calculate average of all grades entered
                    average = (double) total / gradeCounter;
                    // display average with two digits of precision
                    JOptionPane.showMessageDialog( null, "Class average is "
                            + twoDigits.format( average ), "Class Average",
                            JOptionPane.INFORMATION_MESSAGE );
                } // end 'if' part of if...else
                else // if no grades entered, output appropriate message
                    JOptionPane.showMessageDialog( null, "No grades were entered",
                            "Class Average", JOptionPane.cINFORMATION_MESSAGE );
                System.exit( 0 );
        } // end main
        }  // end class averageHere is the resulting output:
    init:
    deps-jar:
    Compiling 1 source file to C:\Java\Average2\build\classes
    C:\Java\Average2\src\average2\Main.java:10: illegal start of expression
    public static void main( String args[] )
    C:\Java\Average2\src\average2\Main.java:73: ';' expected
    } // end main
    C:\Java\Average2\src\average2\Main.java:75: '}' expected
    } // end class average
    3 errors
    BUILD FAILED (total time: 2 seconds).
    Can anyone tell me what I'm doing wrong?
    Thanks in advance

    Hmmm, I put the } in at the end of the code and that got rid of one of the bugs. code now reads:
    package average2;
        import java.text.DecimalFormat;
        import java.swing.JOptionPane;
    public class Main {
        public Main() {
        public static void main( String args[] )
                int total;          // sum of grades
                int gradeCounter;   // number of grades entered
                int grade;          // grade value
                double average;     // number with decimal point for average
                String gradeString; // grade typed by user
                // initialisation
                total = 0;          // initialise total
                gradeCounter = 0;   // initialise gradeCounter
                // processing phase
                // get first grade from user
                gradeString = JOptionPane.showInputDialog( "Enter Student Grade or -1 to Quit:" );
                // convert gradeString to int
                grade = Integer.parseInt( gradeString );
                // loop until sentinal value is reached
                while ( grade != -1 ) {
                    total = total + grade;          // add grade to tatal
                gradeCounter = gradeCounter + 1;    // increment counter
                // get next grade from user
                gradeString = JOptionPane.showInputDialog( "Enter Student Grade or -1 to Quit:" );
                // convert gradeStrin to int
                grade = Integer.parseInt( gradeString );
            }   // end while
                // termination phase
                DecimalFormat twoDigits = new DecimalFormat( "0.00" );
                // if user entered at leat one grade...
                if( gradeCounter != 0 ) {
                    // calculate average of all grades entered
                    average = (double) total / gradeCounter;
                    // display average with two digits of precision
                    JOptionPane.showMessageDialog( null, "Class average is "
                            + twoDigits.format( average ), "Class Average",
                            JOptionPane.INFORMATION_MESSAGE );
                } // end 'if' part of if...else
                else // if no grades entered, output appropriate message
                    JOptionPane.showMessageDialog( null, "No grades were entered",
                            "Class Average", JOptionPane.INFORMATION_MESSAGE );
                System.exit( 0 );
        } // end void main
        } // end main
    //} // end class mainWith the following output:
    init:
    deps-jar:
    Compiling 1 source file to C:\Java\Average2\build\classes
    C:\Java\Average2\src\average2\Main.java:10: illegal start of expression
    public static void main( String args[] )
    C:\Java\Average2\src\average2\Main.java:73: ';' expected
    } // end void main
    2 errors
    BUILD FAILED (total time: 0 seconds)
    I'm really sorry for being stupid. I'm just trying to understand what is going wrong. As soon as I get this sorted I can apply the principle to all other code I'm trying to write. I copied this code directly from my textbook used the SDK. Netbeans dosen't seem to like the way the textbook writes the code!

  • How can use simpler code?

    How can use simpler code for checking a particular value in a string?
    FIND 'C' IN fg_result ."FOR PAYMENT METHODS "CPRS"
    IF sy-subrc NE 0. FIND 'P' IN fg_result.ENDIF.
    IF sy-subrc NE 0. FIND 'R' IN fg_result.ENDIF.
    IF sy-subrc NE 0. FIND 'S' IN fg_result.ENDIF.
    IF SY-SUBRC = 0.

    Dear Shashank,
    DATA:  GV_SRCH(1)    TYPE   C.
    CASE  GV_SRCH.
      WHEN 'C'.
                      FIND 'C' IN fg_result.
      WHEN 'P'.
                      FIND 'P' IN fg_result
      WHEN 'R'.
                      FIND 'R' IN fg_result
      WHEN 'S'.
                      FIND 'S' IN fg_result
    ENDCASE.
    Regards,
    Abir
    Don't forget to award Points *

  • JMS Simple code in Sun tutorial

    I run a simple code (http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JMS4.html) fine in j2sdkee , but fail to use in Openjms/ JBoss.
    try {
    connectionFactory = (ConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
    } catch (Exception e) {
    System.out.println("JNDI API lookup failed: " + e.toString());
    return;
    What's wrong of the above code? Why do I can the following error in Openjms / Jboss?
    JNDI API lookup failed: javax.naming.CommunicationException: Can't find

    OpenJMS by default defines the following: (QueueConnectionFactory is not defined by default!)
    queueName = "queue1"
    queueConnectionFactoryName = "JmsQueueConnectionFactory"
    The creation of the initial context could be done like this
    Hashtable env = new Hashtable ();
    env.put(Context.PROVIDER_URL,
    "rmi://localhost:1099/JndiServer");
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "org.exolab.jms.jndi.rmi.RmiJndiInitialContextFactory");
    jndiContext = new InitialContext (env);
    Similar modifications are needed for JBoss

  • MyRIO simple code compilation FPGA

    Hello,
    I am new to FPGA and I want to compile some simple code. I know that myRIO comes with default FPGA configuration so I want to create new one and compile it. Lets say that I want blinking LED. So I create new VI on FPGA and here is simple code:
    then I add it to build and start compilation
    As compilation goes it says that it will use 30% of FPGA resources:
    Why is that? Whole compilation on cloud server takes more than 20 minutes. I have seen some example videos on CRio FPGA and that simple code should use no more than 2% of resources and shuld compile in 2 to 3 minutes.
    What I am doing wrong?
    Thanks in advice

    Hey Pawhan11,
    There are two main reasons for the FPGA resource consumption.  First is that the FPGA on the myRIO (Zynq Z-7010) is relativly small compared to some other NI targets you may have used.  The second reason that even a simple FPGA application takes ~20% of the FPGA fabric is because some of the FPGA fabric is already being used for other purposes.  For example some NI Real-Time targets implement UARTs, RS232 or even ethernet in the FPGA to ensure consistency between devices. 
    Since myRIO is based on the Xilinx Zynq chip it uses a different toolchain than previous FPGA devices which may cause the difference in compile/synth times.
    -Sam K
    LabVIEW Hacker
    Join / Follow the LabVIEW Hacker Group on google+

  • Trying to retrieve the serial nimber to install software. It says I used incorrect redemption code. I have checked and rechecked. What should I do?

    Trying to retrieve the serial number required to install software for Elements 12. Answer says wrong redemption code. I have checked & rechecked. What shall I do?

    It's pretty convoluted now, but try this page and click where it says "Still need help?"
    Contact Customer Care

  • How do I check "them"????

    This is the code:
    import java.util.*;
    public class FillingLists {
      public static void main(String[] args) {
        List list = new ArrayList();
        for(int i = 0; i < 10; i++)
          list.add("");
        Collections.fill(list, "Hello");
        System.out.println(list);
    } ///:~$ javac FillingLists.java -Xlint:unchecked
    FillingLists.java:7: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
    list.add("");
    ^
    FillingLists.java:8: warning: [unchecked] unchecked conversion
    found : java.util.List
    required: java.util.List<? super java.lang.String>
    Collections.fill(list, "Hello");
    ^
    FillingLists.java:8: warning: [unchecked] unchecked method invocation: <T>fill(java.util.List<? super T>,T) in java.util.Collections is applied to (java.util.List,java.lang.String)
    Collections.fill(list, "Hello");
    ^
    3 warnings
    How do I check "them" so I don't get these warnings anymore???
    Thank you.....

    This is a new warning in jdk 1.5. This means you are not using generics.
    Try
            List<String> list = new ArrayList<String>(10);

  • When I try to download any app my phone says I need to sign in to verify and it takes me to a billing screen. Then it always says my security code is wrong, but it's not

    MY iPhone won't let me download apps, it says I need to sign in and verify account payment options. Even for a free app and then it says my security code is wrong on my credit card! Ugh!! Help please!

    Did you ever get this fixed? I started getting this same message yesterday when changing my card to a debit card that I had used previosuly for years. My last purchase was Saturday morning. Creating a new account results in the same message no matter whar card I try. They must flag accounts by computer ID for this to be happening.
    I got a message stating that my problem has been handed to a senior advisor. I hate this wait especialy since I have had my account since 2003.

Maybe you are looking for