943,747 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 913
  • Java RSS
Apr 29th, 2009
0

encryption / swapping first & third, swap second & fourth digits

Expand Post »
Java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2. public class encryption
  3. {
  4. public static void main (string[] args)
  5. {
  6. int temp, first,second, third, fourth,encryped;
  7. int a = first,b = second,c = third, d = fourth;
  8. int a = c,c = a;
  9. int b = d,d = b;
  10. System.out.println("After swapping a = " + a + "c = " + c)+System.out.println("After swapping c = " + c + "a = " + a)
  11. System.out.println("After swapping b = " + b + "d = " + d)+System.out.println("After swapping d = " + d + "b = " + b)
  12. }
  13. double integer;
  14.  
  15. Scanner scan = new Scanner (System.in);
  16. System.out.print("Enter a four digit integer:");
  17.  
  18. while (integer>0)
  19. {
  20. temp = integer % 1000;
  21. temp+7;
  22. first = temp % 10;
  23.  
  24. temp = integer % 1000;
  25. temp % 100;
  26. temp+7;
  27. second = temp % 10;
  28.  
  29. temp = integer % 1000;
  30. temp % 100;
  31. temp & 10;
  32. temp+7;
  33. third = temp % 10;
  34.  
  35. temp = integer % 1000;
  36. temp % 100;
  37. temp & 10;
  38. temp+7;
  39. fourth = temp % 10;
  40.  
  41. new second = fourth;
  42. first = new third * 1000;
  43. third = temp * 10;
  44.  
  45. temp = new second;
  46. new second = new fourth * 100;
  47. fourth integer = temp;
  48.  
  49. encrypted = first integer + second integer + third integer + fourth integer;
  50. }
  51.  
  52. System.out.println("The Encrypted number is:");
  53. System.in.println("Four digit number:");
  54. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cameclifton is offline Offline
4 posts
since Apr 2009
Apr 29th, 2009
0

Re: encryption / swapping firset&&third, swap seconde&&fourth digits

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.
Last edited by zyaday; Apr 29th, 2009 at 10:22 am.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
zyaday is offline Offline
70 posts
since Jun 2008
Apr 29th, 2009
0

Re: encryption / swapping firset&&third, swap seconde&&fourth digits

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
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Apr 29th, 2009
0

Re: encryption / swapping firset&&third, swap seconde&&fourth digits

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:");


[codeimport 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:");
}
[/code]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cameclifton is offline Offline
4 posts
since Apr 2009
Apr 29th, 2009
0

Re: encryption / swapping firset&&third, swap seconde&&fourth digits

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,

Java Syntax (Toggle Plain Text)
  1. public class BestJewSinceJCExample{
  2. System.out.println("Print me");
  3. public static void main(String[] args){
  4. int a = 0;
  5. System.out.println("a's value is " + a);
  6. }
  7. }

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:

Java Syntax (Toggle Plain Text)
  1. public class BestJewSinceJCExample{
  2. public static void main(String[] args){
  3. System.out.println("Print me");
  4. int a = 0;
  5. System.out.println("a's value is " + a);
  6. }
  7. }

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.
Last edited by BestJewSinceJC; Apr 29th, 2009 at 9:43 pm.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: adding to float value
Next Thread in Java Forum Timeline: Arrays in Java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC