# how can i make the choices 1 2 3 4 to A B C D in java

• July 14th, 2013, 09:29 AM
khianz08
how can i make the choices 1 2 3 4 to A B C D in java
this are my codes.

import java.util.*;

public class test{
public static void main (String [] args ){
Scanner input = new Scanner (System.in);
int b, n1, n2, sum, sub, mul, div, mod;

System.out.print ("Enter first number: ");
n1=input.nextInt();
System.out.print ("Enter second number: ");
n2=input.nextInt();
System.out.println("****************************Ch oose an Operation****************************");

System.out.println("[2] Subtraction");

System.out.println("[3] Multiplication");

System.out.println("[4] Division");

System.out.println("****************************** *********************************************");
System.out.println("Selected Operation");
b=input.nextInt();

if (b==1){
sum=n1+n2;
System.out.print("The Sum is :" + n1 + "&" + n2 +" is " + sum );
}
else if (b==2){
sub=n1-n2;
System.out.print("The sub is :" + n1 + "&" + n2 +" is " + sub );
}
else if (b==3){
mul=n1*n2;
System.out.print("The mul is :" + n1 + "&" + n2 +" is " + mul );

}
else if (b==4){
div=n1/n2;
mod=n1%n2;
System.out.println("The div is :" + n1 + "&" + n2 +" is " + div );
System.out.println("The mod is :" + n1 + "&" + n2 +" is " + mod );

}

}
}
• July 14th, 2013, 11:33 AM
vijayj196
Re: how can i make the choices 1 2 3 4 to A B C D in java
Hi,
You can compare character with its ASCII code because java permits direct comparision
as well as all arithmetic operations on character primitive