Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

Comparative Languages

Posted on October 1, 2023July 14, 2024 By William Jojo
Code

(Updated July 14, 2024)

String name;
int len;

name = "Bill";
len = name.length();

System.out.println(name.charAt(0));
System.out.println(name.charAt(1));
System.out.println(name.charAt(2));
System.out.println(name.charAt(3));
System.out.println("The length of the string is " + len);
String name;
int len;

name = "Bill";
len = name.length();

System.out.println(name.charAt(0));
System.out.println(name.charAt(1));
System.out.println(name.charAt(2));
System.out.println(name.charAt(3));
System.out.println("The length of the string is " + len);
String name;
int len;

name = "Bill";
len = name.length();

System.out.println(name.charAt(0));
System.out.println(name.charAt(1));
System.out.println(name.charAt(2));
System.out.println(name.charAt(3));
System.out.println("The length of the string is " + len);
public class StringsAndChars {

  public static void main(String[] args) {

    //          0123456
    String s = "Abc-128";
    String t = "cHARLIE";
    String name;
    int i;
    char c;
    
    // Test if a letter and determine case
    c = s.charAt(1);
    System.out.println("\nFor the character '" + c + "'");
    System.out.println("Letter: " + Character.isLetter(c));
    System.out.println("Upper : " + Character.isUpperCase(c));
    System.out.println("Lower : " + Character.isLowerCase(c));

    // Test if a digit
    c = s.charAt(4);
    System.out.println("\nFor the character '" + c + "'");
    System.out.println("Digit : " + Character.isDigit(c));
    
    // Change the case of the string.
    c = t.charAt(0);
    name = Character.toUpperCase(c) + t.substring(1).toLowerCase();
    System.out.println("\nName  : " + name);
    
    // Convert a string to int.
    i = Integer.parseInt(s.substring(4)) * 2;
    System.out.println("\ni is  : " + i);

  }
}
public class JavaPrintf {
    public static void main(String[] args) {
        String s = "Hello Java";
        System.out.printf("%s%n", s);
    }
}
#include <stdio.h>

int main() {
    const char s[] = "Hello, World!\n";
    printf("%s\n", s);
    return 0;
}
#include <unistd.h>

int main() {
    const char s[] = "Hello, World!\n";
    write(0, s, sizeof s);
    return 0;
}
.data

/* Data segment: define our message string and calculate its length. */
msg:
    .ascii        "Hello, ARM64!\n"
len = . - msg

.text

/* Our application's entry point. */
.global _start
_start:
    /* syscall write(int fd, const void *buf, size_t count) */
    MOV     x0, #1      /* fd := STDOUT_FILENO */
    LDR     x1, =msg    /* buf := msg */
    LDR     x2, =len    /* count := len */
    MOV     w8, #64     /* write is syscall #64 */
    SVC     #0          /* invoke syscall */

    /* syscall exit(int status) */
    MOV     x0, #0      /* status := 0 */
    MOV     w8, #93     /* exit is syscall #93 */
    SVC     #0          /* invoke syscall */
define CHROUT $ffd2

    ldx #0         ; set index to zero
print:
    lda words, x   ; load a letter from words
    beq done      ; if it's the zero, we're done
    jsr CHROUT    ; print the character
    inx           ; increment the index
    bne print     ; keep printing
done:
    brk           ; end!

; data below this line

words:
    txt "Hello MOS 6502!\n"
    dcb 0

Post navigation

❮ Previous Post: Commodore 64
Next Post: Group Project 2 (of 2) ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.