473,320 Members | 1,920 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,320 software developers and data experts.

Why is wrong with my code???

why is it that when I tried char as input its not printing WORD FOUND.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class fs
  4. {
  5.     public static void main(String args[]) throws IOException
  6.     {
  7.         String [] datatype = new String[4];//{"boolean","byte","char","double","float","int","long","short"};
  8.         String input;
  9.         //int i=0;
  10.         BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
  11.         System.out.print("Enter String: ");
  12.         input = buff.readLine();
  13.  
  14.         datatype[0]="boolean";
  15.         datatype[1]="byte";
  16.         datatype[2]="char";
  17.         datatype[3]="double";
  18.  
  19.  
  20.         for(int i=0;i<datatype.length;i++)
  21.         {
  22.             if(input==datatype[i])
  23.             {
  24.                 System.out.println("WORD FOUND");
  25.                 i=datatype.length;
  26.             }
  27.             else
  28.             {
  29.                 System.out.println("WORD NOT FOUND");
  30.             }
  31.         }
  32.     }
  33. }
  34.  
Dec 4 '11 #1
1 1410
Hi,
use equals method to compare objects.Don't use == to compare the string objects
Dec 14 '11 #2

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

Similar topics

2
by: Wally Sanford | last post by:
http://wallysanford.com is currently being redirected by Namecheap to my server at home. The link to the W3C Validator has been working fine. Suddenly, that link causes the Validator to see and...
7
by: Jerry Krinock | last post by:
I've declared a class that has some std::vector data members like this: class MyClass { public: ... std::vector<Apples> apples ; ... private: ...
3
by: Jeff Cooper | last post by:
Hey Folks, I have a bunch of aspx pages in a solution. One of these pages, call it header1.aspx, has it's code behind in header1.aspx.vb. Another, header2.aspx, has header2.aspx.vb. When I...
6
by: Alvaro G. Vicario | last post by:
The code below inserts a <spantag around the image. It works fine in Firefox or Opera, but has a weird effect in Internet Explorer: browser keeps loading the image forever... Even though the...
14
by: OldBirdman | last post by:
I have 2 ListBoxes, ColumnCount=1 with lbxAlpha1.RowSource = "A";"C";"E"; . . . and lbxAlpha2.RowSource = "B";"D";"F"; . . . All works fine as long as I only use one of the ListBoxes. When I have...
8
by: cube | last post by:
I must sort the below values of table in a specific way. Everytime that I possition a sorted value to the best_time array, I marked it as a "job done" by giving the value 0 to the table...
2
by: brof777 | last post by:
here is the code: DWORD SomeFunction(DWORD Dw_0, DWORD Dw_1, DWORD Dw_2) { return Dw_0 + Dw_1 + Dw_2; } void main() { DWORD Dw = 0; DWORD pDw = {1,2,3}; DWORD Dw_Sum = SomeFunction(pDw, pDw,...
8
by: =?GB2312?B?yum09MXt?= | last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange. so I want to know exactly the inner details of the compiler impletation,if possible. and I...
3
by: canabatz | last post by:
im using paging on this query: i got this code that returning wrong results: (SELECT bid_price, count(*) as n from bidding_details where bid_id=$bid_id GROUP BY bid_price DESC HAVING n = 1 ) ...
2
by: sometingsometing | last post by:
hi, I am new and dont know what went wrong. from Tkinter import * import tkMessageBox from pysqlite2 import dbapi2 as sqlite class door: global simpleprint
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.