0% found this document useful (0 votes)
197 views7 pages

Datatypes

The Java program creates an ArrayList to map letters of the alphabet to their corresponding numerical values. It prompts the user to input a number and then outputs the corresponding letter based on the input. The program includes a series of conditional statements to handle the mapping from numbers to letters.

Uploaded by

api-358397170
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views7 pages

Datatypes

The Java program creates an ArrayList to map letters of the alphabet to their corresponding numerical values. It prompts the user to input a number and then outputs the corresponding letter based on the input. The program includes a series of conditional statements to handle the mapping from numbers to letters.

Uploaded by

api-358397170
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// Import java ArrayList.

//
import java.util.ArrayList;

// Import Java scanner. //


import java.util.Scanner;

public class datatype {

public static void main(String[] args) {


// TODto-generated method stub

// Add alpha ArrayList. //


ArrayList<String>
alpha = new ArrayList<String>();

//Make array of letters to equal numbers //


alpha.add("a = 0");
alpha.add("b = 1");
alpha.add("c = 2");
alpha.add("d = 3");
alpha.add("e = 4");
alpha.add("f = 5");
alpha.add("g = 6");
alpha.add("h = 7");
alpha.add("i = 8");
alpha.add("j = 9");
alpha.add("k = 10");
alpha.add("l = 11");
alpha.add("m = 12");
alpha.add("n = 13");
alpha.add("o = 14");
alpha.add("p = 15");
alpha.add("q = 16");
alpha.add("r= 17");
alpha.add("s = 18");
alpha.add("t = 19");
alpha.add("u = 20");
alpha.add("v = 21");
alpha.add("w = 22");
alpha.add("x = 23");
alpha.add("y = 24");
alpha.add("z = 25");

// Print out alpha array //


System.out.println(alpha.get(0));
System.out.println(alpha.get(1));
System.out.println(alpha.get(2));
System.out.println(alpha.get(3));
System.out.println(alpha.get(4));
System.out.println(alpha.get(5));
System.out.println(alpha.get(6));
System.out.println(alpha.get(7));
System.out.println(alpha.get(8));
System.out.println(alpha.get(9));
System.out.println(alpha.get(10));
System.out.println(alpha.get(11));
System.out.println(alpha.get(12));
System.out.println(alpha.get(13));
System.out.println(alpha.get(14));
System.out.println(alpha.get(15));
System.out.println(alpha.get(16));
System.out.println(alpha.get(17));
System.out.println(alpha.get(18));
System.out.println(alpha.get(19));
System.out.println(alpha.get(20));
System.out.println(alpha.get(21));
System.out.println(alpha.get(22));
System.out.println(alpha.get(23));
System.out.println(alpha.get(24));
System.out.println(alpha.get(25));

// Ask a question //
System.out.println("Type a number");

//Make array of numbers//


ArrayList<Integer>
num = new ArrayList<Integer>();
num.add(0);
num.add(1);
num.add(2);
num.add(3);
num.add(4);
num.add(5);
num.add(6);
num.add(7);
num.add(8);
num.add(9);
num.add(10);
num.add(11);
num.add(12);
num.add(13);
num.add(14);
num.add(15);
num.add(16);
num.add(17);
num.add(18);
num.add(19);
num.add(20);
num.add(21);
num.add(22);
num.add(23);
num.add(24);
num.add(25);

// Make new scanner l //


Scanner l = new Scanner(System.in);
int input = l.nextInt();

// If user types in number print out letter //


if(input == num.get(0)) {
System.out.println("You typed in a");
}
else if(input == num.get(1)){
System.out.println("You typed in b");
}
else if(input == num.get(2)) {
System.out.println("You typed in c");
}
else if(input == num.get(3)) {
System.out.println("You typed in d");
}
else if(input == num.get(4)) {
System.out.println("You typed in e");
}
else if(input == num.get(5)) {
System.out.println("You typed in f");
}
else if(input == num.get(6)) {
System.out.println("You typed in g");
}
else if(input == num.get(7)) {
System.out.println("You typed in h");
}
else if(input == num.get(8)) {
System.out.println("You typed in i");
}
else if(input == num.get(9)) {
System.out.println("You typed in j");
}
else if(input == num.get(10)) {
System.out.println("You typed in k");
}
else if(input == num.get(11)) {
System.out.println("You typed in l");
}
else if(input == num.get(12)) {
System.out.println("You typed in m");
}
else if(input == num.get(13)) {
System.out.println("You typed in n");
}
else if(input == num.get(14)) {
System.out.println("You typed in o");
}
else if(input == num.get(15)) {
System.out.println("You typed in p");
}
else if(input == num.get(16)) {
System.out.println("You typed in q");
}
else if(input == num.get(17)) {
System.out.println("You typed in r");
}
else if(input == num.get(18)) {
System.out.println("You typed in s");
}
else if(input == num.get(19)) {
System.out.println("You typed in t");
}
else if(input == num.get(20)) {
System.out.println("You typed in u");
}
else if(input == num.get(21)) {
System.out.println("You typed in w");
}
else if(input == num.get(22)) {
System.out.println("You typed in x");
}
else if(input == num.get(23)) {
System.out.println("You typed in y");
}
else if(input == num.get(24)) {
System.out.println("You typed in z");
}
else if(input == num.get(25)) {
System.out.println("You typed in z");
}

l.close();

You might also like