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

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2009
Posts: 2
Reputation: cameclifton is an unknown quantity at this point 
Solved Threads: 0
cameclifton cameclifton is offline Offline
Newbie Poster

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

 
0
  #1
Apr 29th, 2009
  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: zyaday is an unknown quantity at this point 
Solved Threads: 1
zyaday zyaday is offline Offline
Light Poster

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

 
0
  #2
Apr 29th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,606
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 205
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

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

 
0
  #3
Apr 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: cameclifton is an unknown quantity at this point 
Solved Threads: 0
cameclifton cameclifton is offline Offline
Newbie Poster

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

 
0
  #4
Apr 29th, 2009
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]
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,606
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 205
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

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

 
0
  #5
Apr 29th, 2009
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,

  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:

  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC