Please correct my Code. I write both the same but still it says "inccorect password"

+1 sharoon amjid · May 1, 2015
import java.util.Scanner;

public class Practice {

public static void main(String args[]) {
Scanner input = new Scanner(System.in);


System.out.println("Please make you password");
String n = input.nextLine();

System.out.println("Your password is Created.\n");

System.out.println("Enter your currently made passowrd");
String m = input.nextLine();


if (m==n){
System.out.println("Congrates its matches");
}else
System.out.println("incorrect password");

}
}

Post a Reply

Replies

Oldest  Newest  Rating
0 sharoon amjid · May 27, 2015
Thank you all very much..
0 Neil Cannon · May 17, 2015
mport java.util.Scanner;
import static java.lang.System.out;

public class Practice {

    public static void main(String args[]) {

        Scanner keybroad = new Scanner(System.in);
        String password;
        String userInput;

        out.println("Please make you password");

        userInput = keybroad.nextLine();

        out.println("Your password is Created.\n");

        out.println("Enter your currently made password");

        password = keybroad.nextLine();

        if (password.equals(userInput)) {
            System.out.println("Congrates its matches");
        } else
            System.out.println("incorrect password");

        keybroad.close();

    }
}


+1 Neil Cannon · May 17, 2015
mport java.util.Scanner;
import static java.lang.System.out;

public class Practice {

    public static void main(String args[]) {

        Scanner keybroad = new Scanner(System.in);
        String password;
        String userInput;

        out.println("Please make you password");

        userInput = keybroad.nextLine();

        out.println("Your password is Created.\n");

        out.println("Enter your currently made password");

        password = keybroad.nextLine();

        if (password.equals(userInput)) {
            System.out.println("Congrates its matches");
        } else
            System.out.println("incorrect password");

        keybroad.close();

    }
}


0 Jake Scaife · May 12, 2015

import java.util.Scanner;


public class Students{
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

String[] iftekhar = { "Subject : BCS", "College Num : 1243",
"Age : 21", "Term : 5th Semester", "Location : Gulberg" };
String[] ali = { "Subject : BCS", "College Num : 8942", "Age : 20",
"Term : 5th Semester", "Location : Gulberg" };
String[] salman = { "Subject : BCS", "College Num : 1245", "Age : 22",
"Term : 5th Semester", "Location : Warsak Road" };
String[] najeeb = { "Subject : BCS", "College Num : 8976", "Age : 20",
"Term : 5th Semester", "Location : Civil Quarter" };
String[] shahbaz = { "Subject : BCS", "College Num : 7854", "Age : 23",
"Term : 5th Semester", "Location : University Road" };

System.out.println("List of students\n");
String[] students = { "iftekhar", "ali", "salman", "najeeb", "shahbaz" };
for (int i = 0; i < students.length; i++) {
System.out.println(students);
}
System.out.println("\nEnter the name of student to see his details");
String name = input.nextLine();

if (name.equals("iftekhar"))
for (int i = 0; i < iftekhar.length; i++) {
System.out.println(iftekhar);
}
else if (name.equals("ali")) {
for (int i = 0; i < ali.length; i++) {
System.out.println(ali);
}
} else if (name.equals("salman")) {
for (int i = 0; i < salman.length; i++) {
System.out.println(salman);
}
} else if (name.equals("najeeb")) {
for (int i = 0; i < najeeb.length; i++) {
System.out.println(najeeb);

}

} else if (name.equals("shahbaz")) {
for (int i = 0; i < shahbaz.length; i++) {
System.out.println(shahbaz);
}

} else
System.out.println("Not matched");

}
}

Consider revising the language.. and programming in general.
0 sharoon amjid · May 2, 2015
Please make this one correct for me: Scenario is I want to select one student from the list and want to see his detail.

import java.util.Scanner;

public class Students {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);

String[] iftekhar = { "Subject : BCS", "College Num : 1243",
"Age : 21", "Term : 5th Semester", "Location : Gulberg" };
String[] ali = { "Subject : BCS", "College Num : 8942", "Age : 20",
"Term : 5th Semester", "Location : Gulberg" };
String[] salman = { "Subject : BCS", "College Num : 1245", "Age : 22",
"Term : 5th Semester", "Location : Warsak Road" };
String[] najeeb = { "Subject : BCS", "College Num : 8976", "Age : 20",
"Term : 5th Semester", "Location : Civil Quarter" };
String[] shahbaz = { "Subject : BCS", "College Num : 7854", "Age : 23",
"Term : 5th Semester", "Location : University Road" };

System.out.println("List of students\n");
String[] students = { "iftekhar", "ali", "salman", "najeeb", "shahbaz" };
for (int i = 0; i < students.length; i++) {
System.out.println(students);
}
System.out.println("\nEnter the name of student to see his details");
String name = input.nextLine();

if (name.equals(iftekhar))
for (int i = 0; i < iftekhar.length; i++) {
System.out.println(iftekhar);
}
else if (name.equals(ali)) {
for (int i = 0; i < ali.length; i++) {
System.out.println(ali);
}
} else if (name.equals(salman)) {
for (int i = 0; i < salman.length; i++) {
System.out.println(salman);
}
} else if (name.equals(najeeb)) {
for (int i = 0; i < najeeb.length; i++) {
System.out.println(najeeb);

}

} else if (name.equals(shahbaz)) {
for (int i = 0; i < shahbaz.length; i++) {
System.out.println(shahbaz);
}

} else
System.out.println("Not matched");

}
}

 
0 Dol Lod · May 2, 2015
No problem.
0 sharoon amjid · May 2, 2015
right right. thanks Arjun :)
0 Dol Lod · May 1, 2015
Welcome to Java where == only works for primitives and memory comparisons. If you want to compare values, use the .equals method for the class. 
  • 1

Java / Android Development

107,177 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator