Heyo13579
Heyo13579

Reputation: 71

Im trying to Create a encryption program but i get errors at the start

// This portion works

    import java.util.Scanner;
      class test {
    private static Scanner inp;
    public static void main(String[] args) {
        inp = new Scanner(System.in);
        System.out.println("Input Password");
        int n = inp.nextInt();
        System.out.println(n);
        if(n!=234) {
            System.out.println("Denied Acess");

        } else { 
            System.out.print("Password Accepted");
        }

Program Errors below and outputs the following

java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match         valid=false]
[need input=false][source closed=false][skipped=false][group separator=\,]
[decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=]
[negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]

/*Pseudocode:
Text: Input Text to Encrypt
            "User Input"
Text: "User input output for test pourposes"
*/
        Scanner enc = new Scanner(System.in);
        System.out.println("Input Text to encrypt");
        System.out.println(enc);
      }
    }

Upvotes: 1

Views: 55

Answers (1)

Paulie
Paulie

Reputation: 7025

import java.util.Scanner;

class Main {
    private static Scanner inp;
    public static void main(String[] args)
    {
        inp = new Scanner(System.in);
        System.out.print("Input Password: ");
        int n = inp.nextInt(); // For int
        System.out.println(n);

        if(n != 234)
        {
            System.out.println("Denied Access");
        }
        else
        {
            System.out.println("Password Accepted");
        }

        /* Scanner has already been initialized, don't create 
           a new one, use existing one, don't try and print the 
           Scanner because it is of type Scanner. */


        System.out.print("Input Text to encrypt: ");
        String m = inp.next(); // For String
        System.out.println(m);
    }
}

Please refer to this for explanation on Scanner class: http://www.javatpoint.com/Scanner-class

Upvotes: 1

Related Questions