Thursday, March 31, 2016

Exercise 1.5

1.5 (Compute expressions) Write a program that displays the result of

9.5 * 4.5 - 2.5 * 3
___________________

45.5 - 3.5

My solution:


public class Ex_one_pt_five {
/*
Author: Brooks Robinson
Problem: (Compute expressions) Write a program that displays the result of

9.5 * 4.5 - 2.5 * 3
___________________

   45.5 - 3.5
*/

public static void main(String[] args) {

System.out.println("The result of \n");
System.out.println("9.5 * 4.5 - 2.5 * 3");
System.out.println("___________________");
System.out.println("    45.5 - 3.5\n");
System.out.println("is: \n");
System.out.println(((9.5*4.5)-(2.5*3))/(45.5-3.5));

} //end of main

} //end of class

Exercise 1.3

*1.3 (Display a pattern) Write a program that displays the following pattern:
        J           A          V        V          A
        J        A   A         V     V         A  A
 J     J      AAAAA        V V         AAAAA
   J J      A            A        V        A           A


My Soultion:
*** This solution formats strangely here but if you paste it into eclipse it should work...***

public static void main(String[] args) {

// output desired string pattern
System.out.println("    J       A     V     V     A   ");
System.out.println("    J   A A     V   V     A A ");
System.out.println("J   J  AAAAA     V V     AAAAA ");
System.out.println(" J J A     A     V     A     A");

} //end of main


} //end of class




Exercise 1.1

1.1 (Display three messages) Write a program that displays Welcome to Java,
Welcome to Computer Science, and Programming is fun.

My Solution:


public class Ex_one_pt_one {

/*
Author: Brooks Robinson
Problem: (Display three messages) Write a program that displays Welcome to Java,
Welcome to Computer Science, and Programming is fun.
*/
public static void main(String[] args) {

// output given strings
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");

} //end of main


} // end of class