import java.util.Scanner;
public class encryption
{
 public static void main (string[] args)
	{
  		int temp, first,second, third, fourth,encryped;
		int a = first,b = second,c = third, d = fourth;
		int a = c,c = a;
		int b = d,d = b;
			System.out.println("After swapping a = " + a + "c = " + c)+System.out.println("After swapping c = " + c + "a = " + a)
			System.out.println("After swapping b = " + b + "d = " + d)+System.out.println("After swapping d = " + d + "b = " + b)
			}
			double integer;
		
	   Scanner scan = new Scanner (System.in);
		System.out.print("Enter a four digit integer:");
		
		while (integer>0)
		{
			temp = integer % 1000;
			temp+7;
			first = temp % 10;
			
			temp = integer % 1000;
			temp % 100;
			temp+7;
			second = temp % 10;
			
			temp = integer % 1000;
					 temp % 100;
					 temp & 10;
					 temp+7;
			third = temp % 10;
			
			temp = integer % 1000;
					 temp % 100;
					 temp & 10;
					 temp+7;
			fourth = temp % 10;
			
			new second = fourth;
			first = new third * 1000;
			third = temp * 10;

			temp = new second;
			new second = new fourth * 100;
			fourth integer = temp;
			
			encrypted = first integer + second integer + third integer + fourth integer;
			}
			
			System.out.println("The Encrypted number is:");
			System.in.println("Four digit number:");
			}

Recommended Answers

All 4 Replies

can u compile your code.it has some errors like temp +7 and staff..not statements;
.it will be much easier to see the problem if u do that first.

Errors:

1. "string" is not a type of Object. It is "String". Change that declaration of public static void main string[] args to public static void main String[] args.
2. You declared a, b, c, and d twice. You can only declare a variable once. Saying 'int whatever' declares a variable called whatever.
3. You can't use System.out.println() + System.out.println(). The reason you can say System.out.println("String" + "other string"); is because that operator can be used to concatenate two Strings. So "String" + "other string" = "Stringother string". This simply isn't allowed for what you did.


etc etc

I made some changes to the code. I compiled the code and these are the errors it is coming up with:encryption.java:17: <identifier> expected

        System.out.println("Enter a four digit integer:");
                                  ^
encryption.java:19: illegal start of type
        while (integer => 0)
                ^
encryption.java:53: <identifier> expected
            System.out.println("The Encrypted number is:");
                                                                      ^
encryption.java:54: <identifier> expected
            System.in.println("Four digit number:");

Code:

import java.util.Scanner;
public class encryption
{
 public static void main (String[] args)
    {
        int a = first,b = second,c = third, d = fourth, encrypted;
        int a = c,c = a;
        int b = d,d = b;
            System.out.println("After swapping a = " + a + "c = " + c);
            System.out.println("After swapping c = " + c + "a = " + a);
            System.out.println("After swapping b = " + b + "d = " + d);
            System.out.println("After swapping d = " + d + "b = " + b);
            }
            double integer;

       Scanner scan = new Scanner (System.in);
        System.out.println("Enter a four digit integer:");

        while (integer => 0)
        {
            temp = integer % 1000;
            temp + 7;
            first = temp % 10;

            temp = integer % 1000;
            temp % 100;
            temp+7;
            second = temp % 10;

            temp = integer % 1000;
                     temp % 100;
                     temp & 10;
                     temp+7;
            third = temp % 10;

            temp = integer % 1000;
                     temp % 100;
                     temp & 10;
                     temp+7;
            fourth = temp % 10;

            new second = fourth;
            first = new third * 1000;
            third = temp * 10;

            temp = new second;
            new second = new fourth * 100;
            fourth integer = temp;

            encrypted = first integer + second integer + third integer + fourth integer;
            }

            System.out.println("The Encrypted number is:");
            System.in.println("Four digit number:");
            }

Yeah, because you are writing code, but it is not inside of any particular method. If you look at where your brackets are located, you will see that those print statements are inside of the class. . but not inside of any method. Put those System.out.printlns and all of the other code that you threw into the class into main or into some other method. For example,

public class BestJewSinceJCExample{
System.out.println("Print me");
   public static void main(String[] args){
   int a = 0;
   System.out.println("a's value is " + a);
   }
}

The code above makes no sense because the main method is executed when the program is run. At what point is the print statement that says "print me" supposed to happen? If you wanted "print me" to be the first thing the program says, then you would have to do the following:

public class BestJewSinceJCExample{
   public static void main(String[] args){
   System.out.println("Print me");
   int a = 0;
   System.out.println("a's value is " + a);
   }
}

Along the same lines, you cannot have random statements and loops (while, for, etc) in the class body. You should only be declaring variables and initializing them in the class body. Anyway, I don't mind helping, but if you are a beginner to Java, you should read some of the tutorials stickied at the top of this forum.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.