| | |
encryption / swapping first & third, swap second & fourth digits
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
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:"); }
•
•
Join Date: Sep 2008
Posts: 1,606
Reputation:
Solved Threads: 205
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
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
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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]
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]
•
•
Join Date: Sep 2008
Posts: 1,606
Reputation:
Solved Threads: 205
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,
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:
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.
Java Syntax (Toggle Plain Text)
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:
Java Syntax (Toggle Plain Text)
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.
Last edited by BestJewSinceJC; Apr 29th, 2009 at 9:43 pm.
![]() |
Other Threads in the Java Forum
- Previous Thread: adding to float value
- Next Thread: Arrays in Java
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






