Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Day12A {
- public static void main(String[] args) {
- int i = 1, n = 5;
- do {
- System.out.println("do while: " + i);
- i++;
- } while (i <= n);
- i = 1;
- while (i <= n) {
- System.out.println("while: " + i);
- i++;
- }
- i = 1;
- for (int j = i; j <= n; j++) {
- System.out.println("for: " + j);
- }
- // i5 n0
- // i1 n1
- }
- }
- //------**********-------------
- public class Day12B {
- public static void main(String[] args) {
- double[] numbers = {9.81, 42, 299.1, -1, 273};
- double sum = 0;
- for (double number : numbers) {
- System.out.println("+ " + number);
- sum += number;
- }
- System.out.println("= " + sum);
- System.out.println("*** for loop version ***");
- double[] numbers2 = {12, 44, 3.75, -4.44, 33};
- sum = 0;
- for (int i = 0; i < numbers2.length; i++) {
- double number = numbers2[i];
- sum += number;
- if (i < (numbers2.length - 1)) {
- System.out.print(number + " + ");
- } else {
- System.out.print(number + " = ");
- }
- }
- System.out.println(sum);
- }
- }
- //------**********-------------
- import java.util.Scanner;
- public class Day12C {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- double newNumber = 0;
- double total = 0;
- //we are limited with what we have discussed
- System.out.println("addition(type 0 to end)");
- do {
- System.out.print("+ ");
- newNumber = sc.nextDouble();
- total += newNumber;
- System.out.println("= " + total);
- } while (newNumber != 0);
- }
- }
- //------**********-------------
- public class Day12D {
- public static void main(String[] args) {
- //para magamit si display method, gagawa tayo ng instance
- // ng class na ito
- Day12D callMe = new Day12D();
- callMe.display();
- //kapag static wala na initialization sa kapwa nya static
- myMethod();
- }
- void display() {
- Day12AccessTest2 callTest2 = new Day12AccessTest2();
- //import galing week1training package
- System.out.println("Hello World!");
- System.out.println("from this folder " + callTest2.bookTitle4);
- System.out.println("from this folder " + callTest2.bookTitle5);
- System.out.println("from this folder " + callTest2.bookTitle6);
- }
- static void myMethod() {
- System.out.println("This is a print from a static method");
- }
- }
- //------**********-------------
- public class Day12AccessTest2 {
- private String bookTitle3 = "Jurassic Park";
- public String bookTitle4 = "The Andromeda Strain";
- String bookTitle5 = "Harry Potter";
- protected String bookTitle6 = "The Hobbit";
- }
Advertisement
Add Comment
Please, Sign In to add comment