English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Am I supposed to add another } at the end of the file?

import java.io.*;

public class rshg {

public static void main(String[] args){
BufferedReader userInput=new BufferedReader (new InputStreamReader(System.in));


String username;
int password;



System.out.println("Enter Username:");

username=userInput.readLine();
if (username!="lene") {

System.out.println("Wrong Username");


}else{

username=userInput.readLine();
if (username=="lene") {
System.out.println("Enter Password");




password=userInput.readLine();
if (password!=123){

System.out.println("Wrong Password");

}else{

System.out.println("Success");

}
}
}

2007-11-08 01:12:42 · 5 answers · asked by Junkie 1 in Computers & Internet Programming & Design

Thank you for your replies, much appreciated!

But what if I need a NOT equals to? For the first portion,

username=userInput.readLine();
if (username!="lene") {

Would it be a
"if (username.!equals("lene")) {

With the !...?

2007-11-08 03:09:44 · update #1

5 answers

Just match { } in the editor like vi.

2007-11-08 01:25:05 · answer #1 · answered by Anonymous · 0 0

This Site Might Help You.

RE:
reached end of file while parsing?
Am I supposed to add another } at the end of the file?

import java.io.*;

public class rshg {

public static void main(String[] args){
BufferedReader userInput=new BufferedReader (new InputStreamReader(System.in));


String username;
int password;



...

2015-08-12 08:24:24 · answer #2 · answered by Lorine 1 · 0 0

You need to add 2 } at the end.
You also need to change this line
if (username=="lene") {
to
if (username.equals("lene")) {

This is because the == for strings and other objects compares the address of the objects.

This line is also wrong
password=userInput.readLine();
The return from readLine() is a string!
Either use parseInt or cast the return value of readLine as an int.

2007-11-08 02:05:15 · answer #3 · answered by AnalProgrammer 7 · 0 0

using do-while loop instead of while loop will solve this prob the problem because when using while loop, u will assign the string terminator value to the variable and process it, that will cause the problem use this : if(result.next() not equal to null) //check if theres at least one element inside the query { do { //ur stuffs here.... //..... //...... } while(results.next() not equal to null); //stop if theres no element left on the query } the syntax is depend on the language u use

2016-03-13 10:33:18 · answer #4 · answered by ? 4 · 0 0

public class rshg
{
public static void main(String[] args)
{
BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
String username;
int password;
System.out.println("Enter Username:");
username=userInput.readLine();
if (username!="lene")
{
System.out.println("Wrong Username");
}
else
{
username=userInput.readLine();
if (username=="lene")
{
System.out.println("Enter Password");
password=userInput.readLine();
if (password!=123)
{
System.out.println("Wrong Password");
}
else
{
System.out.println("Success");

}
}
}
}
}

2014-01-19 05:21:40 · answer #5 · answered by Yogendra 1 · 0 0

fedest.com, questions and answers