Results 1 to 12 of 12
Thread: Small Java program help
- 03-25-2010, 03:41 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
Small Java program help
HI,
im new in java world
and i shoud make this programe
i tried to make it but i couldn't
so,
i hope u to help me
this is the program
4. write a program that reads a string composed of 4 alphabetic characters; the program forms another string comosed of alphabetic characters following those in the first string. Print the resulting string.
Ex: input: dlpw output: emqx
pleaaaaaaaaaase help me
- 03-25-2010, 03:52 PM #2
Post your code. What doesn't work? Where are you stuck?
We certainly won't do your homework for you.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-25-2010, 03:55 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
ok
i don't ask u to do it
just explain it for me
- 03-25-2010, 04:03 PM #4
loop over the String, get every single char, add 1 to each char, put chars into new String, done. Think about what should happen if the input String contains a 'z'.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-27-2010, 05:20 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
can i do it in another way
not loop
-
- 03-27-2010, 05:56 PM #7
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
no but i didn't study it yet
the loop
this is my code but it doesn't work
Moderator Edit: Code tags addedJava Code:import java.util.*; public class Q4 { static Scanner console = new Scanner (System.in); public static void main(String [] args) { String word; char s1,s2,s3,s4; System.out.println(" Entr 4 alphabetic: "); word = console.next(); s1 = word.charAt(1); s2 = word.charAt(2); s3 = word.charAt(3); s4 = word.charAt(4); System.out.print((char)(s1+1)+(char)(s2+1)+(char)(s3+1)+(char)(s4+1)); } }Last edited by Fubarable; 03-27-2010 at 06:01 PM. Reason: Moderator Edit: Code tags added
- 03-27-2010, 06:00 PM #8
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Character positions in Java Strings (and element positions in Java arrays and other ordered collections) begin at position 0, not position 1.
Hope that helps.
-Gary-
-
1) When your code doesn't work, please tell us why as it will make it 1000 times easier to help you.
2) Please use code tags when posting code here. My signature below can help show you how.
3) Your attempt is workable, but please note that the character position in Strings start at 0 not 1.
4) If you want to concatenate characters and show them in a print or println statement, you may want to first have an empty pair of quotes present:
Much luck!Java Code:System.out.println("" + s1 + s2 + s3 + s4);
- 03-27-2010, 06:24 PM #10
Member
- Join Date
- Dec 2009
- Posts
- 7
- Rep Power
- 0
thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaanks
its work now
-
Wonderful! :)
- 03-27-2010, 06:43 PM #12
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Since you have it working now, I will show you how to do it in a loop (and maybe you will be a little bit ahead of your class :cool: ).
Good luck!Java Code:public class Q4a { static Scanner console = new Scanner (System.in); public static void main(String[] args) { String word; char c; System.out.print(" Enter 4 alphabetic: "); word = console.next(); for (int i = 0; i < 4; i++) { c = word.charAt(i); c += 1; System.out.print(c); } } }
-Gary-
Similar Threads
-
Proofreading this small Java program
By almina in forum New To JavaReplies: 5Last Post: 10-23-2009, 07:42 AM -
Small yahtzee program
By kimmelim in forum New To JavaReplies: 20Last Post: 03-12-2009, 12:11 PM -
Small Dice Program
By kimmelim in forum New To JavaReplies: 13Last Post: 02-15-2009, 01:01 AM -
Please HELP Java small program
By afrttoh in forum New To JavaReplies: 14Last Post: 11-08-2008, 02:29 AM -
small issues with a program
By jimJohnson in forum New To JavaReplies: 6Last Post: 04-25-2008, 08:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks