Sunday 14 August 2011

Week 3: Minutes (Monday)

Minutes:
- Variables & types
- Value assignment to variables
- Printing values of variable out
- Operators and their order
- Compositions of operators
- Compositions with printing command
- A lot of examples demonstrated

Code:
public class w3c2 {
public static void main(String[] args) {
//******* Declaration of Variables****//
String val;
int num;
int n1,n2,add,sub,mul,div;
double pwr;
//int double;
double weight;
//********* Variables & Assignment ****//
System.out.print(val);
System.out.print(", number:");
System.out.print(num);
System.out.print(", weighted:");
System.out.print(weight);
//********* Operatiors ****//
n1=8;
n2=2;
add = n1+n2;
sub = n1-n2;
mul = n1*n2;
div = n1/n2;
pwr = Math.pow(n1,n2);
System.out.println("Again, power = " + pwr);
System.out.println("Again, multiplication = " + (n1+n2));
System.out.println("All in order ADD,SUB,MUL,DIV,PWR:" + add + ", " + sub + ", " + mul + ", "+ div + ", " + pwr);
System.out.println("All in order ADD,SUB,MUL,DIV,PWR:" +(n1+n2)+ ", " + (n1-n2) + ", " + n1*n2 + ", "+ n2/n2 + ", " + (Math.pow(n1,n2)));
// Remove parenthesis of all operators
//******* Operators for Strings*******//
/*
String st,st1, st2;
st1 = "We are ";
st2 = "UBD students";
st = st1 + st2;
System.out.println(st1);
System.out.println(st2);
System.out.println(st);
*/
//num = squared(6);
// System.out.println("Value:" + squared(81));
//System.out.println("Value:" + Math.sqrt(5));
//squared(3);
//num = Math.sqrt(5);
//num = squared(5);
//System.out.println("The value" + num);

}


Hints: to make a program to solve a problem, you should think in the top-down analysis:
- what problem do I want to solve?
- how many variable do I need for this problem?
- choose types for the variables
- declare the variables
- use operators with special attention of their order (usually using Parenthesis to make the statement more clear)
- assign simple values for the test
- test and evaluate



No comments:

Post a Comment