Reading String input?

So the other day I thought I might go ahead and try to make a few simple programs to see if anything I have learned is soaking in. I did a few math ones, which were easy enough, but then I tried to do a password program. It was easy enough to write, but the thing is I could only do it with numbers. Although thats alright, I was aiming to do one with Strings rather than ints. Thing is I have no idea how to take the input of a String like an int would (readInt). Heres my short password program involving just ints if it helps any:
package OtherStuff;
import acm.program.ConsoleProgram;
import java.util.*;
public class stringPassword extends ConsoleProgram {
public void run() {
     int password = 2256;
          while (true) {
               int input = readInt("Enter a password: ");
               if (input == password) {
                    println("Password accepted");
                    break;
               if (input != password) {
                    println("Password not accepted\n");
}So all in all, how can I take the input of a String and use it in the same way I use ints in the code above?

jverd wrote:
ldilley wrote:
jverd wrote:
ldilley wrote:
jverd wrote:Reference values, actually.The values stored in reference variables are memory addresses.They may be implemented as such, but it's not required by the spec. The JLS has no concept of a memory address.Required or not, it is what it is. Nobody was questioning specification requirements; albeit the JLS does make mention of addresses of objects. I come from a C background and the concept of memory addressing is how I describe it. Terminology tends to bleed over if you use multiple languages. Regardless, you are wanting to debate about semantics. Let us not digress from the OP's inquiry.It was specifically for the OP's benefit that I brought it up. I've seen too much confusion from people blurring the lines between specification and implementation, and trying to apply concepts from other languages beyond where there's any similarity or any usefulness in doing so.
A reference is simply an opaque value that is used to locate and object. The fact that it's an address is irrelevant. What is it an address of? In current Sun JVMs, I believe it's an address of a pair of pointers. One might say something like, "If you're familiar with addresses or pointers in other languages, you can think of a Java reference as the memory address of the object, even though that's not strictly speaking what it is." I don't see any value in telling a noob that it IS an address though.Making mention of memory addresses is certainly not beyond similarity or usefulness in the scope of this context if that is what you are implying. I do not believe it is irrelevant (I see from many of your posts that you like this word) to help Cypher understand what is going on conceptually. The "cubby holes" visualization of memory certainly helped me in my programming courses. The fact is, there are many people who can use the Web(tm) proficiently without knowing the related RFCs. The same applies to the JLS and programming with Java. It may help if you want to be a pedantic Java lawyer. However, knowledge of this document is definitely not required to use the language productively. So, inversely, I do not see the value in being overly concerned with semantics and the details of the JLS as it could be too restrictive and confuse "noobs".
In fact, there are several college-level textbooks that explain reference variables in terms of memory addresses. "Java Programming: From Problem Analysis to Program Design" by D. S. Malik is one such book. So, again, this is certainly not irrelevant by any means.
Regards,
Lloyd D.

Similar Messages

  • Reading strings and integers from a text file

    I want to read the contents of a text file and print them to screen, but am having problems reading integers. The file contains employee's personal info and basically looks like this:
    Warren Laing
    32 //age, data type is int
    M //gender, data type is String
    Sharon Smith
    44
    F
    Here's what I've done so far. The method should continue reading the file until there's no lines left. When I call it from main, I get a numberFormatException error. I'm not sure why because the data types of the set and get methods are correct, the right packages have been imported, and I'm sure I've used Integer.parseInt() correctly (if not, pls let me know). Can anyone suggest why I'm getting errors, or where my code is going wrong?
    many thanks
    Chris
    public void readFile() throws IOException{
    BufferedReader read = new BufferedReader(new FileReader("personal.txt"));
    int age = 0;
    String input = "";
    input = read.readLine();
    while (input != null){
    setName(input);
    age = Integer.parseInt(input);
    setAge(age);
    input = read.readLine();
    setGender(input);
    System.out.println("Name: " + getName() + " Age: " + getAge() + " Gender: " + getGender());
    read.close();

    To answer your question - I'm teaching myself java and I haven't covered enumeration classes yet.
    With the setGender("Q") scenario, the data in the text file has already been validated by other methods before being written to the file. Anyway I worked out my problems were caused by "input = read.readLine()" being in the wrong places. The code below works fine though I've left out the set and get methods for the time being.
    Chris
    public static void readFile()throws IOException{
    String name = "";
    String gender = "";
    int age = 0;
    BufferedReader read = new BufferedReader(new FileReader("myfile.txt"));
    String input = read.readLine();
    while(input != null){
    name = input;
    input = read.readLine();
    gender = input;
    input = read.readLine();
    age = Integer.parseInt(input);
    input = read.readLine();
    System.out.println("Name: " + name + " Gender: " + gender + " Age: " + age);
    read.close();

  • How can I read an input which only contain the 26 upper case letter

    Are there any method that can read an input which only contain 1 character and it is in upper case too.
    should I use readChar( ), or readString( )??
    How should I implement them if I do use one of them?
    thx

    Try this :
    import java.io.*;
    public class Read
    public static void main(String[] x)
    System.out.println("Upper case char typed : "+readUpperCaseChar());
    public static char readUpperCaseChar()
    // method that read char and return the last upper case char
    char x='\0',tmp='\0';
    try
    while(tmp!='\n')
    tmp=(char) System.in.read();
    if(tmp >= 'A' && tmp <= 'Z')
    x=tmp;
    catch(IOException ioex)
    ioex.printStackTrace();
    return x;

  • Try It mode - string input

    In Try It mode can you have more than 1 string input? I've been playing around with it but without success. For example when the user is inputting text some users put in 1 space after a full stop, others use 2. This will be frustrating to the users. I see that you can add another input string but this only seems to work in Know It mode.
    Cheers.
    Edited by: 800719 on Nov 1, 2010 12:46 AM

    I am experiencing a silimar problem with the action area not showing the same in the See It or Try It mode as when looking at it in the developer. It gets moved up from the actual action area. Since your post was over 2 years ago and there hasn't been any other replies, I'm assuming no one knows of a fix. Please reply if you ever found a solution.

  • Use unvalidated string input fro Tyr it mode?

    I remember from the past I could set an option to "unvalidated string input"for Try it mode as well. Currently the default is set to unvalidate string input entered in Know it and pressing typing complete.
    I wonder if it still is possible to have the Typing complete option in the Try it mode as well.
    Kind regards,
    Sjoerd

    You probably want to post to one of the J2SE forums but I would expect that you would want to read a character at a time and echo it back yourself.
    You should probably check sourceforge.net and/or apache.org as I am sure there is already an implementation that you can utilize

  • Can formula node take string input and output string?

    I am wondering if the formula node can take string input variable and output string variable after calculation. otherwise I have to output integers and then use case structure to select different output strings, that is kind of redundant in coding.
    ping

    If you are just trying to read lines that have mixed formatting, you don't need any script nodes.
    Can you attach a tpyical flne and a description of the desired read operation so we have a better idea what you are trying to do? Do all lines have the same overall format?
    LabVIEW Champion . Do more with less code and in less time .

  • How do you get a program to read an input file?

    I have a problem where i need my program to read an input file and the name of the input file should be read as a command line argument. How in the world do I do this?? I do not have the slightest idea how to get that done? Please help!!

    The command line arguments are stored in the String[] args passed in from the main function.
    To use the argument as a file name, you can create a FileInputStream. To make it easier to read, you can then put the FileInputStream into a BufferedReader to read line by line. For example:
    public static void main(String[] args) {
       FileInputStream fileIn;
       BufferedReader reader;
       try {
          fileIn = new FileInputStream(args[0]);
       catch (FileNotFoundException fnfe) {
          System.err.println("could not find file " + args[0]);
       reader = new BufferedReader(fileIn);   You may now use reader.readLine() to read each line from the file. I hope this helps!
    -JBoeing

  • Using jsp to read a input from a radio button

    i am trying read a input from a radio button ,normly if the name of radio button is "priority" and if u referrence it as request.getParameter("priority") it shld work right but mine does not.
    <% rs = stmt.executeQuery("select PRIORITYNAME,PRIORITYDESC from TBL_PRIORITY ");
    <td>Priority</td>
    <% while(rs.next())
    %>
    <input name="priority" type="radio"><% out.println(rs.getString(1)); %><% out.println(rs.getString(2)); %><br>
    <%
    %>
    is it bcs i am using a loop !! bcs am populating the radio fields from a database

    i am trying read a input from a radio button ,normly
    if the name of radio button is "priority" and if u
    referrence it as request.getParameter("priority") it
    shld work right but mine does not.
    A couple of things not necessarily addressing your problem, but still..
    Avoid too much Java code in the JSP. Use existing tags or write new custom tags to do the task.
    Avoid database access form the JSP itself, if possible.
    <% rs = stmt.executeQuery("select
    PRIORITYNAME,PRIORITYDESC from TBL_PRIORITY ");
    <td>Priority</td>
    <% while(rs.next())
    %>
    <input name="priority" type="radio"><%
    out.println(rs.getString(1)); %><%
    out.println(rs.getString(2)); %><br>
    <%
    %>
    I'm not quite sure what are you trying to do with the above. You want the labels of the radio buttons to be obtained from the database as well as their values, is it?
    Does PRIORITYNAME correspond to the value of the radio button and PRIORITYDESC correspond to the label of the radio button?
    If that's the case, I think you need to do it as follows:
    Radio button is declared as follows in HTML
    <input name="priority" type="radio" value="<%rs.getString(1)"%>><%rs.getString(2)%></input>
    is it bcs i am using a loop !! bcs am populating the
    radio fields from a databaseNo

  • SAP BI - OLAP variable in DTP unable to read from input ready variable in query

    Hello,
    Here's the problem:
    We have a process chain which is launched in a WAD.
    We would like to filter the DTPs in the PC with the values entered in the variable screen of the WAD
    I created a variable of type customer exit X which reads the input ready variable Y in CMOD.
    Customer exit variable X was placed in the filter of the DTP.
    The input ready variable Y in the query contained in the WAD.
    I am getting an error that customer exit variable X is getting not value.
    Is it possible to read an input ready variable in a customer exit variable placed in a DTP?
    Or am I missing a step here?
    Please help.
    Thanks in advance

    Hi Anjalee,
    Maybe it would be good to share a bit more information on your scenario and the chosen solution design. I am currently missing the point of triggering a Process Chain using Web Application Designer.
    Anyway, I recommend to be careful with using OLAP variables in DTP filters. For sure not all functionality is present, e.g. because the variable pop-up is absent. Your constellation of an input ready variable and a customer-exit variable will only work in the context of a BEx Query and probably not if used in a DTP filter.
    Best regards,
    Sander

  • Error while executing SSIS package - Error: 4014, Severity:20, State: 11. A fatal error occurred while reading the input stream from the network. The session will be terminated (input error: 109, output error: 0)

    Hi,
    We are getting the following error when running our SSIS packages on Microsoft SQL Server 2012 R2 on Windows Server 2008 R2 SP1:
    Error: 4014, Severity:20, State: 11.   A fatal error occurred while reading the input stream from the network. The session will be terminated (input error: 109, output error: 0)
    SQL Server Data Tools and SQL Server Database Engine reside on the same server.
    We tried the following:
    Disabling TCP Chimney Offload
    Installed Windows Server 2008 SP1
    Splitting our SSIS code into multiple steps so it is not all one large continuous operation
    The error occurs during a BulkDataLoad task.
    Other options we are investigating with the engineering team (out-sourced, so delayed responses):
    Firewall configurations (everything is local, so this should not make a difference)
    Disabling the anti-virus scanner
    Are there other things we can try?
    Any insight is greatly appreciated.
    Thanks!

    Hi HenryKwan,
    Based on the current information, the issue can be caused by many reasons. Please refer to the following tips:
    Install the latest hotfix based on your SQL Server version. Ps: there is no SQL Server 2012 R2 version.
    Change the MaxConcurrentExecutables property from -1 to another one based on the MAXDOP. For example, 8.
    Set "RetainSameConnection" Property to FALSE on the all the connection managers.
    Reference:
    https://connect.microsoft.com/SQLServer/feedback/details/774370/ssis-packages-abort-with-unexpected-termination-message
    If the issue is still existed, as Jakub suggested, please provide us more information about this issue.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Error 4014 Severity 16 State A fatal error occurred while reading the input streamfrom the network

    We encounter following error intermittently Error 4014 Severity 20 State 16 , A fatal error occurred while reading the input stream from the network
    I have checked the RING_BUFFER_CONNECTIVITY from sys.dm_os_ring_buffers, we are able to find the remote_host IP where connections are being closed/killed, the error being logged in sys.dm_os_ring_buffers, comes from multiple remote_host, we have raised
    to O/s and Networking Team they seem to have no clue, why this error occurs
    Server: Virtual Machine
    Operating System: WINDOW 2008 R2 SP1
    MSSQL 2008 STD ED SP3 10.0.5850.0
    Database mirroring is configured for the application database.
    Antivirus enable on the database server
    How do we find the cause for this error being logged in SQL server logs, is this error due to SQL database mirroring or memory issue?
    What needs to be checked on the O/s and Network, I have been checking on the internet and everywhere it is pointing to NIC drivers or security patches
    Also in the system events following error was being logged, but after restarting the vm service this error has not re-occurred
    A timeout (30000 milliseconds) was reached while waiting for a transaction response from the VMTools service
    Kindly suggest on Error 4014 Severity 20 State 16, A fatal error how to resolve
    [email protected]

    Hello,
    Could you try to use Network Monitor or WireShark to examine if the connections resets are coming from a client computer
    or from the host where SQL Server is installed?
    Network Monitor can be downloaded from the following link:
    http://www.microsoft.com/en-us/download/details.aspx?id=4865
    If you use Network Monitor trace you will identify connection resets by looking for “TCP: Flags=,,R.A” at the description column on the Frame Summary. Once you find the flag, the Source column will tell you the identity of the host resetting the connection,
    maybe is not the SQL Server host.
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Read only af:inputText being rendered as "span" instead of read only input

    I am using JDeveloper 11.1.1.6.0
    I have noticed that when using components such as "af:inputText" and "af:inputDate" with the "readOnly" attribute set to true, the resulting render is a label as a "<span>" element as opposed to a read only <input> element which I would have expected. I see the expected behavior if I utilize the JSF "h:inputText" component with "readOnly" set to true, however I cannot utilize the JSF component as it does not appear as though I can get "autoSubmit" behavior to work with the JSF component so that will not work. To add on to the oddness of the behavior, if the af:inputText has its Rows attribute set to be greater than 1, it will render as a read only <input> element as opposed to a label.
    In addition, the af:inputText's default readOnly form looks glaring when using the simple skin or other skins based on simple. It adds a box that wraps around the exact length of the text in the inputText as opposed to the amount of area that the inputText would have consumed if it was not in "readOnly" mode.
    Is there any way to properly get the af:inputText to render as a read only input as opposed to the label that it is currently being displayed as?
    Thank you.

    Hi,
    its a decision made by the component renderer. If this is a problem for you and if you have a customer support contract then you could file a service request for a change.
    Frank

  • OVS on read-only input field

    OVS will not allow me to change the value of a read-only input field.  If the input field is set to read-only, the OVS selection table does not display an 'OK' button, only close.
    Value cannot be copied (field is not editable)
      I do not want the field to be editable on the screen, but only allow input via the selected row in the OVS.  Any suggestions?
    Edited by: Bob DeNuto on Jul 31, 2008 1:22 AM

    Using Dictionary Search Help and OVS in this case will disable the Copy button and you don't have any control.
    Use Freely Programmed Value Help, this will solve your problem
    https://wiki.sdn.sap.com/wiki/display/WDABAP/Freelyprogrammedinput+help
    how to provide f4 help to the read only input field
    Abhi

  • Sysgen : How to read the input port data type, width and rate dynamically in a masked subsystem ?

    Hello everybody,
         I am designing a general purpose block in system generator. I pass the user parameters to the block through masking it. Some user parameters can change the block configuration. The input port data type, width and rate can also affect the block configuration.
         The problem is that these values (input port data type, width and rate) are subject to change. So I should read them dynamically, then change the block configuration through programming the "Initialization Commands" field. But unfortunately there is no straight way to read the input port information.
         There are some methods in for example the "Black Box". these are:
    input_width = this_block.port('din').width;
    input_rate = this_block.port('din').rate;
    But these methods are not applicable to a masked subsystem.
    I have tried other ways also. You can find them below. None of them worked.
    Does anybody know how can I solve this problem?
    Other ways I tried:
    1)
    design_name([],[],[],'compile')                                       
    q=get_param(gcb,'PortHandles');
    get_param(q.Inport,'CompiledPortDataType')
    get_param(q.Inport,'CompiledPortWidth')
    get_param(q.Inport,'CompiledPortDimensions')
    design_name([],[],[],'term')
    2)
    ssGetInputPortDataType
    3)
    ts = Simulink.Block.getSampleTimes([gcb '/Input'])
     

    Today we rely on Simulink to perform parameterization of your designs in two ways:
    Parameterizable Subsystems and Blocks : Parameters themselves can be MATLAB expressions that need to be evaluated for which we need the MATLAB interpreter
    The very useful Rate and Type propagation or Simulink compilation that allows us to specify types & rates in one location that gets systematically propagated to all.
    To truly make the HDL Netlist that is generated from SysGen parameterizable, we would have to implement some of this capability in the HDL netlist itself by:
    Using Generics(VHDL) or Parameters(Verilog) - We would have to capture the bit width(type) propagation through levels of hierarchies and finally parameterize the IP itself based on this value
    Since IP itself does not have this capability through generics, we would have to package a separate tcl script that updates the IP parameterization appropriately in response to top level parameters(or GUI parameters)
    Interpreting MATLAB expressions and translating them into VHDL/Verilog expressions (alternatively tcl expressions of IP). In simulink, mask parameters can be passed from one level to the next. Also parameterization of a block can be composed of Matlab expressions using variables from ancestor masks & the MATLAB interpreter – so we will need to somehow capture that as well.
     

  • How to read the 'Input help with fixed values' of domain .

    How to read the 'Input help with fixed values' of domain .
    The domain has a Value range i want to read those values .
    Are these values stored in any table ?
    Plz help me i need it ver badly...
    Thanks in Advance...

    Hi Chandra Shekhar,
    To read the 'Input help with fixed values' of domain , you can use the function module : HR_P_GET_FIXED_VALUE_TEXT.
    iIf you enter the domain name, you will find the fixed values entered in the domain.
    These values are stored in a table DD07L(DD zero 7 L). Here the values are stored based on domain name.
    See if it works for you.
    Award points if its helpful.
    Regards,
    Bhanu

Maybe you are looking for

  • Using B2B as file / ftp gateway

    We have a need to reach out various ftp servers and retrieve files. We can do it in BPEL directly, but i was wondering if it is possible for b2b server to go out to these ftp servers and retrieve the files on a scheduled basis ?

  • XI - SAP R3 - XI Scenario

    I have a scenario JMS 1 -> XI (BPM 1) -> SAP R3 -> XI (BPM 2) -> JMS 2 (all interfaces are synchronous) I found when BPM 2 is triggered, it doesn't work until timeout (PL_TIMEOUT). But if I only run SAP R3 -> XI (BPM 2) -> JMS 2, then it's ok. The co

  • Set Dynamic Default Delivery Date in ME21n

    Hi! Under personal settings in ME21n, it is possible set a default delivery date. However, as I see it one can only set a fixed date like 2011-08.-12, which would quite useless in a couple of weeks. Is there any way to set this date dynamically as it

  • WHEN or HOW to fix the problem with Thunderbolt/Side screen problems

    WHEN or HOW to fix the problem with Thunderbolt/Side screen problems (Cinema screen). Keeps blinking on & off then eventually completely off. Would have thought Apple would have fixed the problem by now as it is apparently to do with the Thunderbolt

  • Non-Compliant Issue

    Can anyone explain to me why the following item is considered non-compliant on this list? It states for the reason that it could not find a compatible TPM, but when you look at the details it clearly shows that it is encrypted and that TPM is the pro