473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I convert the numbers of ASCII to character by easier way?

Hi

I'm a beginner on Java

so I hope you guys can help me

Expand|Select|Wrap|Line Numbers
  1. int a1 = str.charAt(0)+1;
  2. int a2 = str.charAt(1)+1;
  3. int a3 = str.charAt(2)+1;
  4. int a4 = str.charAt(3)+1;
  5.  
  6.  
  7. System.out.print("output :");
  8. System.out.print((char)a1);
  9. System.out.print((char)a2);
  10. System.out.print((char)a3);
  11. System.out.println((char)a4);
  12.  
I want to know how to write (char)a1,(char)a2 ... (char)a4 in one System.out.print
also I want to know how can I write (char)a1 outside of the System.out.print, I mean
???? = (char)a1

please help :)
Sep 28 '13 #1
2 1313
stdq
94 64KB
Answering your first question, I think you can do this:

Expand|Select|Wrap|Line Numbers
  1. System.out.print( (char)a1 + ", " + (char)a2 + ", " + (char)a3 + ", " + (char)a4 )
Regarding your second question, you want to assign (char)a1 to a char variable?
Sep 28 '13 #2
Luuk
1,047 Expert 1GB
Lines 1..4 can be done like this:
Expand|Select|Wrap|Line Numbers
  1. anArray = new int[4];
  2. for (int x=1; x<=4; x++) {
  3.   int a[x] = str.charAt(x-1)+1;
  4. }
  5.  
this seems longer, but when you do it more than 4 times it gets shorter (than the original way) ;)

Also your lines 8..11 can be done insize a 'for'-loop.
Sep 28 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: David Williams | last post by:
Hi all, i have been able to convert an ASCII character to an INT however im lost as to how to change them back. Cant find anything on the net (though im probably looking in the wrong places!)....
2
by: jt | last post by:
Looking for an example how to convert and CString to an ASCII character string. Any examples on how to do this? Thank you, jt
37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
3
by: Director - Minvent | last post by:
Hi, I am reading from a serial port from a device which sends over an ascii character. It uses the full extended 256 character set and therefore has non-printing characters too. So what i want...
18
by: Marcel Saucier | last post by:
Hello, I want to use the above characters codes chart but I dont know how to set the typeface (documentation: The characters that appear in Windows above 127 depend on the selected typeface). ...
16
by: akarui.tomodachi | last post by:
What is the most easiest way to convert an integer value to ASCII character format ? I tried with sprintf(). It works. Is there any other way to do that ? Objective:: I like to convert an...
1
by: keithb | last post by:
How can I convert an ascii code into a character using C# in ASP.NET? Thanks, Keith
9
by: simchajoy2000 | last post by:
Hi, I know what the ASCII Character Codes are for the 2nd and 3rd powers in VB.NET but I can't find the 6th power anywhere - does anyone know what it might be or if it even exists? Joy
6
by: bruce | last post by:
hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii...
6
by: davetelling | last post by:
I am a total newbie, trying to slog through the Visual C# Express application. I need to be able to convert a single ASCII character (can be anything from 0 to 255) to an int for use in other...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.