Results 1 to 4 of 4
Thread: illegal character: \92
- 06-29-2008, 08:34 AM #1
Member
- Join Date
- Jun 2008
- Location
- Ontario Canada
- Posts
- 2
- Rep Power
- 0
illegal character: \92
I had my application working just fine and all I did was change the phrase in my System.out.println() and now I get this error. I changed everything back to the original and still get this error on each of my statements. TestNumbers.java:18 illegal character:\92 double num1 = input.nextDouble(); \\This will give input a double type. It will throw an exception if letters are added. Why did it work once? Can someone help as this assignment is due on Monday. Code follows
import java.util.*;
//this class does the required calculation as requested
public class TestNumbers
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.println();
System.out.println("Enter a number that is a double:");
double num1 = input.nextDouble(); \\This will give input a double type. It will throw an exception if letters are added
System.out.println();
System.out.println("Enter a number that is a float:");
float num2 = input.nextFloat(); \\This will give input a float type. It will throw an exception if letters are added
System.out.println();
System.out.println("Enter a number that is a long:");
long num3 = input.nextLong(); \\This will give input a long type. It will throw an exception if letters are added
System.out.println();
System.out.println("Enter a number that is an integer:");
int num4 = input.nextInt(); \\This will give input an int type. It will throw an exception if letters are added
System.out.println();
System.out.println("Enter a number that is a byte:");
byte num5 = input.nextByte(); \\This will give input a byte type. It will throw an exception if letters are added
float result1 = num2 - num4;
double result2 = result1 * num1;
double result3 = result2 / num3;
double result4 = result3 * num5;
double result5 = result4 / 2;
int result = (int)result5; \\to be sure result is an integer, it is expicitly stated
System.out.println();
System.out.println("Result of (float-int)*double/long*byte/2 is:\n\n" + result);
}
}
- 06-29-2008, 08:44 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Error in comments. Change \\ into // and see.
- 06-29-2008, 08:52 AM #3
Member
- Join Date
- Jun 2008
- Location
- Ontario Canada
- Posts
- 2
- Rep Power
- 0
I feel so stupid. It worked before I commented. Thanks! At 63 years old I find this course really hard but am enjoying it. Hopefully this forum will keep me out of the insane asylum.
- 06-29-2008, 09:04 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice! If you solve the question please mark the thread as solved.
Similar Threads
-
illegal character: \65279
By iwax in forum New To JavaReplies: 3Last Post: 01-30-2008, 02:52 PM -
reading text character by character
By bugger in forum New To JavaReplies: 2Last Post: 11-09-2007, 08:54 PM -
Illegal Start of an Expression
By David55 in forum CLDC and MIDPReplies: 8Last Post: 11-02-2007, 09:11 PM -
Illegal start of expression
By gabriel in forum New To JavaReplies: 2Last Post: 08-01-2007, 05:09 PM -
Illegal Start of an Expression
By David55 in forum CLDC and MIDPReplies: 0Last Post: 04-20-2007, 05:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks