|
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);
}
}
|