int cannot be derefrenced? java question!

MasterSamwise

Senior member
Jan 12, 2003
219
0
0
Code:
import cs1.Keyboard;

public class ch3_6
{

public static void main (String[] args)
{


	int i, q; // counter, user input
	char x; // char for testing pos/neg/0

	System.out.println ("enter a value");
	q = Keyboard.readInt ();


	while (q >= 1)
18	x = q.charAt (q, i);
		i++;

	System.out.println (x);



	}

}

I get the error int cannot be derefrenced on line 18. Any ideas? I am trying to split an inputed int into chars. System.out.println (x) should print the value of the character through each run of the loop. Eventually i will need to use a switch statment to assign different cases for x but first i need to figure out why my .charAt method isn't working.

Any java programmers?

MasterSamwise
 

MasterSamwise

Senior member
Jan 12, 2003
219
0
0
Updated code. Still getting the derefrenced error.

import cs1.Keyboard;

public class ch3_6
{

public static void main (String[] args)
{


int i, q, even, odd, zero; // counter, user input
char x; // char for testing odd/even/0


// get user input

System.out.println ("enter a value");
q = Keyboard.readChar ();

// use charAt for each run of loop with counter i

while (q >= 1)

{
x = q.charAt (q, i);
i++;

// print the char values of x on seperate lines for each run of the loop

// System.out.println (x);

switch (x)
{
case 1:
x = ('0');
System.out.println ("zero");
zero ++;
break;

case 2:
x = ('1');
System.out.println ("odd");
odd ++;
break;

case 3:
x = ('2');
System.out.println ("even");
even ++;
break;

case 4:
x = ('3');
System.out.println ("odd");
odd ++;
break;

case 5:
x = ('4');
System.out.println ("even");
even ++;
break;

case 6:
x = ('5');
System.out.println ("odd");
odd ++;
break;

case 7:
x = ('6');
System.out.println ("even");
even ++;
break;

case 8:
x = ('7');
System.out.println ("odd");
odd ++;
break;

case 9:
x = ('8');
System.out.println ("even");
even ++;
break;

case 10:
x = ('9');
System.out.println ("odd");
odd ++;
break;

default:
System.out.println ("error");
break;
}

}
System.out.println ("Even: " + even);
System.out.println ("Odd: " + odd);
System.out.println ("Zero: " + zero);

}

}

anyone help me on this one?
 

PrincessGuard

Golden Member
Feb 5, 2001
1,435
0
0
q is an integer primitive. It does not have a charAt() method, so q.charAt() is invalid.

Instead of reading in a char or int from Keyboard, see if you can read in a String. If that's not supported by your class, then look up the Integer class in the Java docs.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |