i have to write a code that has a random number generated between 1-100 and the user has the choice to keep the number, discard the number and quit the program. and when the user quits the program displays the numbers kept and discarded, but i dont know how to use the character input for the user to chose. this is what i have Inline Code Example import java.util.*; public class Lab1A{ public static void main(String [] args){ int input=0; int K = 0; int D = 0; char Q = 0; for (int i=0; i<100; ){ double random = Math.random(); double x = random*100; int y = (int)x + 1; //Add 1 to change the range to 1 - 100 instead of 0 - 99 System.out.print("Random Number: "); System.out.print(y); System.out.println("\nEnter Option: (K, D, Q): "); char option = (char)input; if (option == K){ } if (option == D){ } if (option == Q){ System.exit(Q); } } } } Here

import java.util.*;
public class Lab1A{
	public static void main(String [] args){
		
		int input=0; 
		int K = 0; 
		int D = 0; 
		char Q = 0;
		
		
	
	for (int i=0; i<100; ){
	 double random = Math.random();

	    double x = random*100;

	    int y = (int)x + 1; //Add 1 to change the range to 1 - 100 instead of 0 - 99

	    System.out.print("Random Number: ");
	    System.out.print(y);
	    
	    System.out.println("\nEnter Option: (K, D, Q): ");
	    char option = (char)input;

Use a Scanner to read the users input. If you read a single char you can compare it in an if test, but you need quotes round the constant, eg

char in = ...
If (in == 'K') ...

Edited 1 Year Ago by JamesCherrill