Results 1 to 6 of 6
- 06-24-2012, 11:46 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
The code is compiling but it is not giving the expected output.
Java Code:import java.util.Scanner; public class ProjectTools { public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.println("Enter the key"); int key = scan.nextInt(); System.out.println("Enter the text"); String text = scan.next() ; String x = "aa"; String ciphertext = encrypt( text , key); System.out.println("ciphertext" + ciphertext); } private static String encrypt(String str , int key){ if (key < 0) { key = 26-(-key%26); } String result = "" ; for (int i = 0 ; i<str.length() ; i++){ char ch = str.charAt(i); result+= encryptchar(ch, key); } return result; } private static char encryptchar(char ch , int key){ if (Character.isUpperCase(ch)) { return ((char) ( 'A'+ ((ch-'A'+key)%26))); } return ch ; } }
- 06-25-2012, 01:42 AM #2
Re: The code is compiling but it is not giving the expected output.
You forgot to tell us what output you expect, and what you get.
Also, go through Code Conventions for the Java Programming Language: Contents -- your indenting is all over the place.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-25-2012, 01:49 AM #3
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: The code is compiling but it is not giving the expected output.
input:
aaa
output:
aaa
but i expect from my code ddd.
- 06-25-2012, 10:10 AM #4
Re: The code is compiling but it is not giving the expected output.
Describe what you expect your encryptchar(char ch , int key) to return when ch isn't an uppercase letter.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-25-2012, 12:00 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: The code is compiling but it is not giving the expected output.
I figure that out.
Thank you.
- 06-25-2012, 12:02 PM #6
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Why is out.println giving me a compiling error?
By dragstang86 in forum New To JavaReplies: 5Last Post: 06-20-2011, 02:37 AM -
output giving null, methods not reading properly
By csuever in forum New To JavaReplies: 22Last Post: 04-01-2011, 02:13 AM -
output not as expected.What's wrong?
By abdullahansari in forum New To JavaReplies: 1Last Post: 12-03-2010, 08:01 PM -
Help please! .class expected when compiling JUnit test?
By tfitz666 in forum New To JavaReplies: 2Last Post: 12-31-2009, 12:45 PM -
output not what expected!
By aza101 in forum Java AppletsReplies: 0Last Post: 07-10-2009, 06:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks