Regarding Code competition quesion!

I came across a Code competition quesion and i have done it.
But i haven't got any idea to how to validate the inputs(Checking whether the inputs are string or not!!!!!!!!!!!)
the following is my code:
import java.io.*;
class cup
     int length,width,height;
     String name;
     cup()                    //default Constructer
          length=0;
          width=0;
          height=0;
          name=" ";
     cup(String n,int l,int w,int h) //Constructer with 4 parameters
          length=l;
          width=w;
          height=h;
          name=n;
     int getvolume()
          return length*width*height; //Calculate the volume of every Cup
public class jelly
     static int no;
     static cup a[];
     static String part[];
     public static void main(String args[])
          System.out.println("Enter no of cups and details:");
          getsize();
          if(no>0)
               cal();     
               while(no!=0){
                    System.out.println("Enter no of cups and details or enter 0 to exit:");
                    getsize();
                    if(no>0)
                         cal();     
     static void cal()
          cup min,max;
          a=new cup[no];
               for(int i=0;i<no;i++)
                    a=getcup();
               min=max=a[0];
               for(int k=1;k<no;k++)
                    if(min.getvolume()>a[k].getvolume())
                         min=a[k];
                    else if(max.getvolume()<a[k].getvolume())
                         max=a[k];
                    if(min.equals(max))
                         System.out.println("No Child Has Lost Jelly!");
                    else
                         System.out.println(min.name+" has lost jelly to "+max.name);
     static void getsize()
     try     
          DataInputStream in=new DataInputStream(System.in);
          String no1=in.readLine();                         //Get The number of cups
          no=validateno(no1);
     catch (Exception e)
     static cup getcup()
     try
          DataInputStream in=new DataInputStream(System.in);
          String tot=in.readLine();
          String na=" ";
          String le=" ";
          String wi=" ";
          String hi=" ";
          int k,l,w,h;
          String ar[]=tot.split(" ");
          na=ar[0];
          le=ar[1];
          wi=ar[2];
          hi=ar[3];
          l=Integer.parseInt(le);
          w=Integer.parseInt(wi);
          h=Integer.parseInt(hi);
     cup c=new cup(na,l,w,h);
          return c;
     catch (Exception e)
          return null;
     static int validateno(String n)
          int n_stud;
          try{
          n_stud=Integer.parseInt(n);
          catch(Exception e)
               System.out.println("Enter numerical value!");
               return -1;
          if(n_stud>100||n_stud<0)
               System.out.println("Enter no between 0 and 100!");
               return -1;
          return n_stud;
/*********I just want to add the following SIMILAR code with out making a error:***********/
static int validate_name(String n)
          if(n.length()>10)
               System.out.println("Enter a name less than 10 characters!");
               return -1;
          return 0;
CAN ANYONE GIVE ME A ANSWER??????????????????????!
BY THE WAY WHEN I COMPILED MY CODE IT GIVES ME A WARNING
CAN ANYONE GIVE ME A ANSWER??????????????????????

I came across a Code competition quesion and i have done it.
But i haven't got any idea to how to validate the inputs(Checking whether the inputs are string or not!!!!!!!!!!!)
the following is my code:
import java.io.*;
class cup
     int length,width,height;
     String name;
     cup()                               //default Constructer
          length=0;
          width=0;
          height=0;
          name=" ";
     cup(String n,int l,int w,int h)           //Constructer with 4 parameters
          length=l;
          width=w;
          height=h;
          name=n;
     int getvolume()
          return length*width*height;      //Calculate the volume of every Cup
public class jelly
     static int no;
     static cup a[];
     static String part[];
     public static void main(String args[])
          System.out.println("Enter no of cups and details:");
          getsize();
          if(no>0)
               cal();     
               while(no!=0){
                    System.out.println("Enter no of cups and details or enter 0 to exit:");
                    getsize();
                    if(no>0)
                         cal();     
     static void cal()
          cup min,max;
          a=new cup[no];
               for(int i=0;i<no;i++)
                    a=getcup();
               min=max=a[0];
               for(int k=1;k<no;k++)
                    if(min.getvolume()>a[k].getvolume())
                         min=a[k];
                    else if(max.getvolume()<a[k].getvolume())
                         max=a[k];
                    if(min.equals(max))
                         System.out.println("No Child Has Lost Jelly!");
                    else
                         System.out.println(min.name+" has lost jelly to "+max.name);
     static void getsize()
     try     
          DataInputStream in=new DataInputStream(System.in);
          String no1=in.readLine();                         //Get The number of cups
          no=validateno(no1);
     catch (Exception e)
     static cup getcup()
     try
          DataInputStream in=new DataInputStream(System.in);
          String tot=in.readLine();
          String na=" ";
          String le=" ";
          String wi=" ";
          String hi=" ";
          int k,l,w,h;
          String ar[]=tot.split(" ");
          na=ar[0];
          le=ar[1];
          wi=ar[2];
          hi=ar[3];
          l=Integer.parseInt(le);
          w=Integer.parseInt(wi);
          h=Integer.parseInt(hi);
     cup c=new cup(na,l,w,h);
          return c;
     catch (Exception e)
          return null;
     static int validateno(String n)
          int n_stud;
          try{
          n_stud=Integer.parseInt(n);
          catch(Exception e)
               System.out.println("Enter numerical value!");
               return -1;
          if(n_stud>100||n_stud<0)
               System.out.println("Enter no between 0 and 100!");
               return -1;
          return n_stud;
/*********I just want to add the following SIMILAR code with out making a error:***********/
static int validate_name(String n)
          if(n.length()>10)
               System.out.println("Enter a name less than 10 characters!");
               return -1;
          return 0;
CAN ANYONE GIVE ME A ANSWER??????????????????????!
BY THE WAY WHEN I COMPILED MY CODE IT GIVES ME A WARNING
CAN ANYONE GIVE ME A ANSWER??????????????????????

Similar Messages

  • 5 question regarding code in DW

    hi
    1 - can i can make php code completion to appear automatically as i write and not use the annoying ctrl+space? just like it does for html and css?
    2- where can i change the font size of the code i write?
    3- where can i change the code formatting for php? like if i prefer the curly braces to appear on its own lines?
    5- regarding code completion. is there a way that when i start a php string it will complete the other '? so when i say: echo ' , it will put the end '?
    4- is there a way to create ducomentation for php? like there is in other IDE`s?
    best regards

    derrida wrote:
     1 - can i can make php code completion to appear automatically as i write and not use the annoying ctrl+space? just like it does for html and css?
    Variables, classes, and objects appear automatically as soon as you start typing. For functions, you need to press Ctrl+Space.
    3- where can i change the code formatting for php? like if i prefer the curly braces to appear on its own lines?
    Dreamweaver does not support source formatting in server-side languages or JavaScript. If you want the curly braces on separate lines, format the code manually as you type it.
    5- regarding code completion. is there a way that when i start a php string it will complete the other '? so when i say: echo ' , it will put the end '?
    Use the echo button in the PHP category/tab of the Insert panel/bar.
    4- is there a way to create ducomentation for php? like there is in other IDE`s?
    No, Dreamweaver does not support PHPDoc.
    If you would like any of these features added to Dreamweaver, submit a feature request through the form at https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform.

  • Regarding code inspector performance check

    Hi all,
    we encountered the following issue in code inspector
    the parameter e_t_range is an internal table . and is tranferred as a value in general, this combination  does not perform well.it appears to be no tranfer . use reference transfer.
    we are writing the code in function module and the e_t_range is one of the importing parameter of function module.
    we are appending the output to e_t_range (table). we r getting the output.
    but we r getting the following performance issue in code inspector.
    please respond to this issue immediately  awaiting for reply.its very urgent********

    hi,
           U r passing Table1 by pass by value which will pass table1 with its contents into another same table type tabel2. the calculation of FM will be done on tale2 not in table1.after getting some calculation into FM tbale 2 will be passed to table1.
    Now if u r passing table by pass by reference then it will pass a address of table1 to FM and within FM's calculation original table1 will get changed directly by using passed address without using another table.
       now in pass by value it uses two internal table thats why it gives performance issue. but yes as said above in RFC u will have to use Pass by value options.
    regards,
    SKumar

  • Regarding Code Generation By Creator

    Hi Creator Team,
    This is not a bug, but in increasing the readability I have a suggestion in generating the code
    Currently creator is doing something like below
    private HtmlForm form1=new HtmlForm ();
    I agree there is nothing wrong with the code
    but if we have method something like initComponents it would be better and increases the readability
    my idea is something like below
    private HtmlForm form1=null;
    public HtmlForm getForm1()
    return this.form1;
    public void setForm1(HtmlForm form1)
    this.form1=form1;
    private void initComponents() throws FacesException
    form1=new HtmlForm ();
    public MyConstructor()
    try{
    initComponents();
    catch(Exception ex)
    }Why I like this model is, it increases the readability and if there is a chance of getting exceptions, you can catch them in constructor and can do further jobs.
    This is not possible with the current creator application
    Hope you understand my concern
    Best Regards
    Sudhakar Chavali

    Hi Sudhakar,
    We thank you for your valuable feedback. An RFE has been filed on your behalf for the same.
    Cheers
    Giri :-)

  • Regarding code protection

    Hi,
    My requirement is For a customized tcode which I create I need to hide the code.
    If some one click on the program name to copy the code, it should say the code is protected.you can not see the code.
    Please suggest me how to do this.
    Swami.

    Hi,
    Please try this way from url: http://www.sap-img.com/abap/program-to-hide-abap-source-code-and-protects-it.htm
    regards,
    Thien

  • Regarding Code inspector

    Hi,
    I am new to code inspector. I just worked on enhancement using BADIs.
    1) What is the purpose of Code inspector ?
    2) How can I use code inspector for my particular code inside one of the BADI method ?
    Please throw some light on this.

    Hi Tushar,
    These links gives you a good idea about what the code inspector does.
    1. <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/nw/a-c/code%20inspector%20user%20manual">Code Inspector User Manual</a>.
    2. <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/nw/how%20to%20build%20a%20new%20check%20for%20the%20code%20inspector">How to Build a New Check for the Code Inspector</a>
    3. <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/evaluating%20the%20quality%20of%20your%20abap%20programs%20and%20other%20repository%20objects%20with%20the%20code%20inspector">Evaluating the Quality of Your ABAP Programs and Other Repository Objects with the Code Inspector</a>
    Regards,
    Anand Mandalika.

  • Regarding code

    Please correct this code
    public class obj{
    private String objval;
    public obj(String val)
    objval=val;
    public String tostring()
    return objval;
    public static void Change(obj o,int i);
    o.objval="value 2";
    o= new objval("value3");
    o.objval="value 4";
    i=2;
    public class q{
    public static void main(String args[])
    obj o=new obj("value1");
    int i=1;
    Change(obj o,int i);
    System.out.println("o="+o+"i="+i);
    Regards,
    Narvish

    as u told i changed prog
    public class obj {
    private String objval;
    public obj(String val)
    objval=val;
    public String tostring()
    return objval;
    public static void Change(obj o,int i);
    o.objval="value 2";
    o= new objval("value3");
    o.objval="value 4";
    i=2;
    class q{
    public static void main(String args[])
    obj o=new obj("value1");
    int i=1;
    o.Change(newVal,2);
    System.out.println("o="+o+"i="+i);
    errors:
    obj.java:12: missing method body, or declare abstract
    public static void Change(obj o,int i);
    ^
    obj.java:15: cannot resolve symbol
    symbol : variable o
    location: class obj
    o.objval="value 2";
    ^
    obj.java:16: cannot resolve symbol
    symbol : variable o
    location: class obj
    o= new objval("value3");
    ^
    obj.java:16: cannot resolve symbol
    symbol : class objval
    location: class obj
    o= new objval("value3");
    ^
    obj.java:17: cannot resolve symbol
    symbol : variable o
    location: class obj
    o.objval="value 4";
    ^
    obj.java:18: cannot resolve symbol
    symbol : variable i
    location: class obj
    i=2;
    ^
    obj.java:26: cannot resolve symbol
    symbol : variable newVal
    location: class q
    o.Change(newVal,2);

  • Help regarding code

    hi, i have problem in coding for the below situation. please help me in this regard.
                                    aravind.
    Name          Code name                 No
      --              Master                    -
      --              Master                    -
      --              Visa                      -
      --              Master                    -
    --                Master                    -
    Write code for Knowing how many master and visa records present in local file

    Hai Aravind
    Go through the following
    DESCRIBE - return attributes of an internal table
    Basic form
    DESCRIBE TABLE itab.
    Effect
    Returns the attributes of the internal table itab . You must use at least one of the additions listed below.
    Additions
    1. ... LINES lin
    2. ... OCCURS n
    Addition 1
    ... LINES lin
    Effect
    Places the number of filled lines of the table t in the field lin .
    Example
    DATA: BEGIN OF TAB OCCURS 10,
            X,
          END OF TAB.
    DATA: LIN TYPE P.
    CLEAR TAB. REFRESH TAB.
    MOVE '?' TO TAB-X.
    APPEND TAB.
    DESCRIBE TABLE TAB LINES LIN.
    Result: LIN contains the value 1.
    Addition 2
    ... OCCURS n
    Effect
    Transfers the size of the OCCURS parameter from the table definition to the variable n .
    Example
    DATA: BEGIN OF TAB OCCURS 10,
            X,
          END OF TAB.
          OCC TYPE P.
    DESCRIBE TABLE TAB OCCURS OCC.
    Result: OCC contains the value 10.
    Note
    If the table is meant to accept more lines than specified by the OCCURS parameter, the parameter value is roughly doubled as long as the table size remains smaller than 8 KB; this table area is held in the roll area. If the table exceeds the maximum permitted size, the OCCURS parameter is not increased and the remaining part of the table is rolled out to the paging area (see DATA ).
    For this reason, the OCCURS value determined by the DESCRIBE statement may differ from that in the DATA statement.
    The runtime required to execute the DESCRIBE TABLE statement is approx. 4 msn (standardized microseconds).
    Regards
    Sreeni

  • Regarding code over view

    Hi  frinedz,
    plz help me any one .
    briefly explain how to select and how to link one table with another with loops and inner joins depending on below requirements
    selection screen fields:company code
                              sales org
                             plant :from-to
                              invoice no:from-to
                             date range; from-to
    1 take the plant code of the billing documents selected from VBRP-WERKS and refer table T001W, where VBRP-WERKS=T001W-WERKS.
    GET adress number from T001W-ADRNR and refer table ADRC, WHERE:T001W-ADRNR=ADRC-ADDRNUMBER.
    get the name of the plant from ADRC-NAME1.
    get the T001W-LAND1 and T001W-REGIO, and get the satte code by refering table T005U.
    2.FROM THE INVOICE NUMBERS GENERATED out of the selection parametres,take up the billing document numbers from table VBRK with the following parameters.
    VBRK-FKDAT
    VBRK-FKART=F2(BILLING TYPE)
    THE BILLING DOCUMENT SHOULD BE OF THE EQUIPMENTS MATERILAS.
    3.TAKE the billing document creation date from tableVBRP,for the given document number being populated in the report
    4.the material level details are required ,goto table VBRP.the table would be referenced with the VBRK-vbelen field,where VBRK-VBELN=VBRP-VBELN.
    5.TAKE THE value of the material from VBRP only
    6.take the delivering plants region code from table VBRP.VBRP-WERKS-PLANT CODE.since the description of the region is required, goto table TOO1W.input the following:
    VBRP-WERKS=T001W-WERKS
    7.since the customer name is required. take from KNA1.table KNA1 is referenced from using the customer code from table VBRP-KUANG, where VBRP-KUNAG=KNA1-KUNNR
    8. ship to customers region is required , we need to identify FROM kna1
    9.LR number from VTTK
    10.LR date , transporter no from VTTK table

    selection screen fields:company code
    sales org
    plant :from-to
    invoice no:from-to
    date range; from-to
    1 take the plant code of the billing documents selected from VBRP-WERKS and refer table T001W, where VBRP-WERKS=T001W-WERKS.
    GET adress number from T001W-ADRNR and refer table ADRC, WHERE:T001W-ADRNR=ADRC-ADDRNUMBER.
    get the name of the plant from ADRC-NAME1.
    get the T001W-LAND1 and T001W-REGIO, and get the satte code by refering table T005U.
    -->
    SELECT VBRP-WERKS T001W-ADRNR T001W-LAND1 T001W-REGIO
    into table itab
    FROM VBRP inner join T001W on VBRP~WERKS = T001W-WERKS.
    Loop at itab.
      SELECT NAME1 into ITAB-NAME1 FROM ADRC WHERE
      ADDRNUMBER = ADRNR.
      SELECT BEZEI into ITAB-BEZEI from T005U WHERE
      spras = sy-langu and land1 = itab-land1 and
      regio = itab-regio.
      modify itab.
    endloop.
    -->
    Message was edited by: Anurag Bankley

  • Regarding code to call & control a  JVM from another JVM

    hi,
    I need to communicate from one JVM to another JVM. I know it can be done using RMI. But, i don't to write in code.If any one had tried it, please reply me with the code.
    Satchi

    Hi Satchi,
    In my opinion, RMI is complex enough that I don't think you can learn it through a forum. So please allow me to direct you to some Internet resources that I used in order to learn RMI, and I hope will help you to as well.
    [Note: Not in any particular order.]
    http://java.sun.com/docs/books/tutorial/rmi/index.html
    http://developer.java.sun.com/developer/onlineTraining/rmi/
    http://java.sun.com/products/jdk/rmi/
    http://www.dickbaldwin.com/tocadv.htm
    http://mindprod.com/jglossrmi.html#RMI
    http://jinx.swiki.net/263
    Hope this helps.
    Good Luck,
    Avi.

  • Regarding code page conversions

    Hi ,
    I have a query on code pages in unicode evironment.
    first of all sorry for big mail on my question
    There were a couple of issues when we have upgraded from 4.7 to 6.0 . These issues were mainly in the code page conversions from one code page xxxx to yyyy and the dataset transfers.
    the problem which im facing is trying to understand  exactly what is this code page doing in the back ground  and these multilingual conversions all about .
    there is a custom code page that my client has made in his landscape and now in majority of the interfaces we need to handle the code based on this code page .
    for ex in the open dataset statement we add legacy text mode code page p_code ignoring conversion errors message lv_message .
    i see some of  the characters especially scandinivian korean chinese and japanese giving some major problem during the file transfers to unix and ftp environment .
    case 1.
    now we are referring to a custom code page 9xxx . now take a character as ä  , now when i write a transfer statement
    with referene to this code page it is displaying as #  in unix path.
    now taking the hexa decimal value of this character if i search in the custom code page (tcode scp with the hexa value of such characters )  there is a value already present  in this code page  9xxx, now when i have a value maintained why am i gettina a #  in the unix server .. how to check the consistency /validity of this code page 
    case 2.
    some hungarian characters like o with a tilt on top cause conversion error dumps during the transfer . again the code page has this hexa value in it .
    why in this case  the conversion from 4102(basically utf-16)
    to code page 9xxx is failing . why it is calling 4102 in this case ?
    ignoring conversion error bypasses this strange chars (cxsycodepage*dump)  but how to hold the correct value at any point of time in the desired server i mean at last i need to transfer o with a tilt instead of a # .
    Please give some in depth  work around solution instead of some vague answers .
    Will appreciate your effort and time for this .
    Thnx much .
    Br,
    Vijay.

    hi
    I am facing same problem when reading the file from application server.It gives me short dump.Can u tell me how can i resolve the code page error issue.In dump analysis i am getting error "NOt able to covert code page '4110' to '4102'

  • Regarding Code signing to my jar

    How to code sign(assign certificate) to my Java Desktop Application.
    plz reply

    i have a jnlp web start aplication, now everyone can access them and get my aplication, i need add some security, so we someone try to install the aplication by the jnlp file the server ask for user/password and it is posible go to de data base and authenticate this user, if the user is correct he can download all the jars and run the aplication.
    i hope you can understand my problem
    plz reply
    Thanks in Advance!!!

  • Regarding codes

    Hi,
    Im technical consultant in implementation project.Now my problem is in Tcode QS41 .When im trying to create code in code group it is not saving the codes under group.
    Example is if i create group as SM01
                                              IN that i need to add newentries (like any with '1234' or 'xyz1') under that it is accepting but unable to save those entries in that.It is possible in IDES but it is not possible in my Development.
    Please let me on this issue.
    best solution should be reverted
    thank u in advance

    HI ravi,
      refer this link
    Using BAPI_PRODORDCONF_CREATE_HDR

  • Help regarding code for title change

    Hi All,
    I have a requirement like whenever we change the PO ie., when we change the  line item data say for example, if there is a quantity like 20kg and if we want to update itto 30kg., the PO will be changed.
    In such change cases, the title of the PO should be changed to "Purchase Order Change". 
    In these cases, the changes will be recorded in the table CDHDR and CDPOS.
    Can anyone pl tell me of how to write the code for this in the script as well as in the subroutine ...
    Help will be rewarded the best..

    Done. Found out the solution

  • This is regarding code for a count up timer.....

    I have created a custom count up timer and I have written the code. But I would like for the dynamic text "0" that I created in Flash to be the counter not some random number that pops up when I initiate the counter. What do I need to do for it to recognize the "0" I typed in a text field as where it should started counting? Does this make sense?
    Here is the code:
    var startT:Number = 1;
    var endT:Number =8000000;
    var tf:TextField = this.createTextField('counter', this.getNextHighestDepth(), 10, 10, 300, 22);
    onEnterFrame = function ()
        if (startT >=endT)
            delete onEnterFrame;
            tf.text = String(endT);
        else
            tf.text = String(startT);
            startT += 1;

    I get that but what I'm saying is I have a typed number "0" in my counter that I would like it to count up, instead I enter the code and test it and out to the left appears another 0 which is smaller and black and it begins to count up... hopefully this is more clear.

Maybe you are looking for

  • Iconcertcal will not let you open Itunes through Front Row

    Itunes has not been opening through Front Row. I just got off the phone with tech support, and it was because of an Itunes download called iconcertcal. As soon as I removed it, everything worked fine! I don't see it listed on the Apple website anymor

  • Schema tool simply doesn't output anything

    In what situations does the ant schematool not output anything and simply let the ant script continue? I have the following piece of ant script: <antcall target="compile"/> <taskdef name="schematool" classname="com.solarmetric.modules.integration.ant

  • Fixing at aggregate level & unfixing at detailed level.

    Hi, Our requirement is as given below...... Our Demand Planning Process is Top-down process. Head Quarter will enter the demand at Territory, Channel and Product Group Level. These values are fixed and gets disaggregated to further planning level bas

  • Adobe Dynamic Link will not work - Premiere Pro CS4 to After Effects CS4

    Hello,    I am edited a video with a deadline, I'm importing a sequence from Premiere Pro CS4 to After Effects and making edits in After Effects. I'm able to import the Premiere Pro sequence into After Effects using Dynamic Link, but  I go back to Pr

  • Clarifications on ISE Hardware (SNS-3415)

    Hi Experts, Good Day! I just want to have some clarifications if what I did in my installation it correct. Basically, my I connected 3 cables in my SNS3415 for my ISE and below is the arrangement of the cables 1 cable is connected to the port dedicat