Q:

How can I prevent the user from entering the same text twice

This program basically calculates the gpa, by letting the user enter the number of courses and course code, with the relevant credit and marks. If the course code is entered twice, a message will show (the course is already registered), and it will keep looping until the user has entered all courses with a different course code 
I have created two methods. One to check if the code is already registered and the other for calculating the gpa, the first method that checks the user input, I'm not sure about it. Because if I entered the course code twice it will only show the message and would allow me to calculate the rest 
public static boolean checkCourse(String[] courseList, String code){
    boolean check = false;
    for(int i=0 ; i < courseList.length; i++){
        if(code.equals(courseList[i])) 
            check = true;
        else
            check = false;
     }
     return check;
}

public static double gradeValue(double marks){
     double grade = 1.0;
     if(marks >=95){ grade = 5.0;}
     else if (marks >= 90) { grade = 4.75;}
     else if (marks>=85) { grade = 4.5;}
     else if (marks >= 80) { grade = 4.0;}
     else if (marks >= 75) { grade = 3.5; }
     else if (marks >= 70) { grade = 3.0;}
     else if (marks >= 65) {grade = 2.5 ;}
     else if (marks >= 60) { grade = 2;}
     else if (marks < 60) { grade =1 ;}
      return grade;
}

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter number of courses: ");
    int n = input.nextInt();
    String[] Courses = new String[n];
    int sumOfcreadit=0;
    int sumOfmarks =0;

    for(int i =0; i<Courses.length;i++){
        System.out.print("Enter a course code: ");
        Courses[i] = input.next();
        if(checkCourse(Courses,Courses[i])){
            System.out.println("the course already registered");
            i--;

        }

        System.out.print("Enter a credit: ");
        int credit = input.nextInt();
        System.out.print(" Enter a marks: ");
        int marks = input.nextInt();

        sumOfcreadit += credit;
        sumOfmarks +=marks * credit;

    } 
    double TotalMarks;
    TotalMarks = sumOfmarks /sumOfcreadit;

    System.out.println("The GPA is: "+gradeValue(TotalMarks));
}

A:

I made some changes in your code and now it works. Changes are described in below code. There was 3 important changes.
I tried to make as less changes as possible to make your code work as expected
public static boolean checkCourse(String[] courseList, String code) {
    boolean check = false;
    for (int i = 0; i < courseList.length; i++) {
        if (code.equals(courseList[i])) {  // equals instead of == to compare strings
            check = true;
            break; // you have to break loop if it is true because else statement before returned false even if there was the same course code due to null values in next array elements which was not filled yet
        }

    }
    return check;
}

public static double gradeValue(double marks) {
    double grade = 1.0;
    if (marks >= 95) {
        grade = 5.0;
    } else if (marks >= 90) {
        grade = 4.75;
    } else if (marks >= 85) {
        grade = 4.5;
    } else if (marks >= 80) {
        grade = 4.0;
    } else if (marks >= 75) {
        grade = 3.5;
    } else if (marks >= 70) {
        grade = 3.0;
    } else if (marks >= 65) {
        grade = 2.5;
    } else if (marks >= 60) {
        grade = 2;
    } else if (marks < 60) {
        grade = 1;
    }
    return grade;
}

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter number of courses: ");
    int n = input.nextInt();
    String[] Courses = new String[n];
    int sumOfcreadit = 0;
    int sumOfmarks = 0;

    for (int i = 0; i < Courses.length; i++) {
        System.out.print("Enter a course code: ");
        String code = input.next();
        if (checkCourse(Courses, code)){
            System.out.println("the course already regestered ");
            i--;
            continue; // continue is neccessary to let user write value again if it already exists
        }
        Courses[i] = code;
        System.out.print("Enter a credit: ");
        int credit = input.nextInt();
        System.out.print(" Enter a marks: ");
        int marks = input.nextInt();

        sumOfcreadit += credit;
        sumOfmarks += marks * credit;

    }
    double TotalMarks;
    TotalMarks = sumOfmarks / sumOfcreadit;

    System.out.println("The GPA is: " + gradeValue(TotalMarks));

}

