Skip to content

CoderSales/Notes-on-Initial-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Notes-on-Initial-Programming

Description

Notes-on-Initial-Programming

Table of Contents of Brightspace Module

Lecture 1

Lecture 2 (not found)

Lecture 3

Lecture 4


Lab Week 5

no later content than this on 2023-10-16-at-1529h

Content

Week-6

Lecture-Week-6

Digital Ocean

Let’s look at the available format specifiers available for printf:

%c character

%d decimal (integer) number (base 10)

%e exponential floating-point number

%f floating-point number

%i integer (base 10)

%o octal number (base 8)

%s String

%u unsigned decimal (integer) number

%x number in hexadecimal (base 16)

%t formats date/time

%% print a percent sign

% print a percent sign

ChatGPT3_5

In the System.out.printf method in Java (and similar formatting in other programming languages), the % symbol is used to indicate a placeholder for a value to be inserted into the string being formatted. The characters following % specify the formatting for the value

that will be inserted.

In the example "%9.7f":

% indicates the start of the formatting specifier.

9 specifies the minimum width of the field where the value will be inserted. In this case, it's saying that the minimum width is 9 characters. If the inserted value is less than 9 characters wide, it will be padded with spaces to the left.

.7 specifies the precision for floating-point numbers. It indicates that 7 decimal places should be shown.

f specifies that the value being inserted should be formatted as a floating-point number.

So, in summary, %9.7f is a formatting specifier for a floating-point number with a minimum width of 9 characters and 7 decimal places of precision.

public class PrintPi {
    public static void main(String[] args) {
        double piValue = Math.PI;
        System.out.printf("Value of PI to 7 dec is %9.7f\n", piValue);
    }
}
System.out.printf("Value of PI to 4 dec is %9.4f\n", Math.PI);
System.out.printf("Value of PI to 2 dec is %-9.2f\n", Math.PI);

W6 Lec PART 2
ASCII Table

ChatGPT3_5

In Java, you can utilize the Character class to work with characters and perform the mentioned operations. Here's a brief guide on using Character for the specified tasks:

Checking if a Character is a Digit:

java Copy code char ch = '7'; boolean isDigit = Character.isDigit(ch); Checking if a Character is a Letter:

char ch = 'A';
boolean isLetter = Character.isLetter(ch);
Checking if a Character is Uppercase:
char ch = 'C';
boolean isUppercase = Character.isUpperCase(ch);
Checking if a Character is Lowercase:
char ch = 'd';
boolean isLowercase = Character.isLowerCase(ch);
Converting a Character to Lowercase or Uppercase:
char ch = 'A';
char lowercaseCh = Character.toLowerCase(ch);
char uppercaseCh = Character.toUpperCase(ch);
Generating a Random Uppercase Letter:
char randomUppercase = (char) ('A' + (int) (Math.random() * 26));
These functions allow you to manipulate and determine properties of characters in Java. Let me know if you need further clarification or additional code examples!

Storing Data (Fixed)

Storing Data (Dynamic)

In fixed size rep var point at data

in dyn var point at ref pointing at date

... if change to the date the reference might change....


Refrerences

Printf

geeksforgeeks Printf

digital ocean Printf

ASCII Table