Reputation: 55
I am new in programming. My instructor gave me a special project about number base.
Since the higher number base are a combination of integers and letters, I'm still confused if I should use int
and/or char
.
import java.util.Scanner;
public class JavaProgram {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the base you want to convert and base to be converted: ");
int firstBase = in.nextInt();
int secondBase = in.nextInt();
switch(firstBase) {
case 2:
System.out.print("Enter value: ");
// I get confused here already
case 3:
case 4:
case 5:
case 8:
case 10:
case 12:
case 16:
case 20:
case 24:
case 26:
case 27:
case 30:
case 32:
case 36:
}
in.close();
}
}
Upvotes: 0
Views: 3737
Reputation: 319
Here is a quick overview of some types:
char
- only a single letter or characterint
- numbers only without decimalsdouble
- numbers with decimalsString
- both numbers and lettersSo based on your requirement you have to select String
.
Upvotes: 1
Reputation: 3420
If you want to store numbers and letters, than you can use char
, since technically letters and numbers are characters. Alternatively you can use String
, which can store anything from a single character, to complete paragraphs.
Upvotes: 2