473,410 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

it's output is wrong!help me please..

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  public class lawAy
  3.  {
  4.      public static void main(String args[])
  5.      {
  6.          String input=null;
  7.          Scanner in=new Scanner(System.in);
  8.          System.out.println("Cno law-ay?");
  9.          input=in.next();
  10.          if(input=="ryka")
  11.          {
  12.              System.out.printf("Correct");
  13.          }
  14.          else
  15.          {
  16.              System.out.printf("Wrong");
  17.          }
  18.     }
  19. }
  20.  
if you type ryka the output should b correct..
Jan 9 '10 #1
1 1075
pbrockway2
151 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. if(input=="ryka")
Try

Expand|Select|Wrap|Line Numbers
  1. if(input.equals("ryka"))
equals() is true if two strings are made up of the same sequence of characters, like the 10th and 14th and 24th words of this sentence. Of course they are different words - none of them could be left out - but they are equal() in terms of the characters that they are made up out of. == on the other hand is only true when the objects are identical: the very same object.

Usually you will use equals() rather than ==.

(When you post code, select the code and use the little # button at the top of the panel to wrap it in code tags. That way it will be better formatted when it appears here.)
Jan 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Stephan Hoffmann | last post by:
Hi, I use XML mainly as a source for HTML. HTML browsers 'know' certain entity references like é or ä. When I use XSL to transform XML to HTML or XML, these entities are replaced...
2
by: Ben Chivers | last post by:
I have a problem, which I think can be easily solved somehow. I am trying to execute a C program through using a PHP script. I do this by sending an exec command from the PHP script. My PHP...
12
by: unique | last post by:
I have written some programs in c lang yet but today I get confused with output i get. I have function educate(..) which i call in main program this way: J = educate(no_layers, no_neurons,...
2
by: Kyle0654 | last post by:
I've been searching for a solution to this problem for a while but haven't hit upon anything yet. Details: Using: MSVC++ .NET 2003 App type: Windows Forms Application (Managed C++)...
2
by: UJ | last post by:
I have a drop down list that I want to have when a certain value has been selected, another set of controls becomes visible. I've done it using radio buttons but I don't know how to do it with a...
14
by: howa | last post by:
void reverse_string(char *str) { if (str == NULL) return; char tmp; size_t len = strlen(str); size_t mid = (int) len / 2; for (size_t i = 0; i < mid; i++) {
16
by: liking C lang. | last post by:
How to write a C programming that it may output the char one after one every other second? For example: char a="hello world!" output h,next second output e,next second output l...
1
by: clairelee0322 | last post by:
I am a c++ beginner and i am working on a dice loop lab. This program should roll two dice (each dice is from 1 to 6) and then total them together. The user should be able to input how many times...
46
by: Kenny O'Clock | last post by:
This came up in a job interview, what is the output of the program below? I tried to compile and run it myself, but my compiler (lcc-win32) aborts with this errors.... Warning test2.c: 3 ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.