Saturday, June 27, 2009

The Hello World


"hello world" was the first program that I did in intprog class.

its actually very simple

public class Hello
{
public static void main (String[]args)
{
System.out.println("Hello World");
}
}

After writing that in the notepad, you have to type Hello.java .<-- i often forget this
the outcome of the screen must have a "Hello World" written on it.

note:
" " - is for strings
' ' - for char
true or false- Boolean
System.out.println- will be shown on the next line
System.out.print- will be on the same line

I learned that this is very important.. knowing the use of modulo and division.
given: n=12345

n/10=1234
n/100=123
n/1000=12
n/10000=1

n%10=5
n%100=45
n%1000=345
n%10000=2345

Honestly, this was very confusing and i didn't think that it was possible for a program to find the middle number in a given.Although the solution was given by our prof Mr.Inventado, I tried doing it.
so here's what i did

public class Mid
{
public static void main(String [] Args)
{
int n=12345;
int mid;
mid= (n/100)%10;
System.out.println ( " With the given number:" + n);
System.out.println ( " the middle number is: " + mid);
}
}
i also learned that % and / can also be used in converting military time to standard time.
Here's the solution from our intrprog prof , Mr. Inventatdo.

public class Time
{
public static void main(String [] Args)
{
int giv=1545;
int hr= giv/100%12;
int min= giv%100;
String zero= min<10? "0": " " ; System.out.println ( hr + " : " + zero + min);
}
}

2 comments:

  1. Most number manipulation algorithms would probably use the % and / so if ever you encounter problems like that, hint hint na yun na baka % or / :D {1 ORP} for you :)

    ReplyDelete
  2. ah thanks ok po, i'll try not to forget that =)

    ReplyDelete