Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DataType {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- // byte short int long
- // double float char boolean
- // String can store a sentence, word etc.
- // type name = value
- String S = "11";
- // String is a reference data type
- // reference data type has functions
- // S.valueOf
- // S.charAt
- // S.length()
- // S.compareTo(anotherString)
- System.out.println(S.length());
- int A = 11;
- if (A==11) {
- System.out.println("equals");
- }
- if (S.equals("11")) {
- System.out.println("equals");
- }
- String T = "ABC";
- //Task 1
- //output T's length
- System.out.println(T.length());
- //Task 2
- //if T equals to ABC
- //output "YES"
- //else output "NO"
- if (T.equals("ABC")) {
- System.out.println("YES");
- } else {
- System.out.println("NO");
- }
- // String E = "I am good";
- // if E contains "good"
- // output YES
- // else output NO
- String E = "I am good";
- if (E.contains("good")) {
- System.out.println("YES");
- } else {
- System.out.println("NO");
- }
- //01234
- String F = "ABCDE";
- //index position
- System.out.println(S.charAt(0));
- //using charAt to output D
- System.out.println(S.charAt(3));
- //using charAt to output E
- System.out.println(S.charAt(4));
- String K = "I am Cindy";
- //using function substring
- //to output "Cindy" from K
- System.out.println(K.substring(5,10));
- //input a String and store into
- //variable J
- Scanner sc = new Scanner(System.in);
- String J = sc.nextLine();
- System.out.println(J);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement