Saye, Abang berase simpati jike ade sape2 yang belum tahu atau belum dapat siapkan assignment tu..Kalau dah siap,Abang ucapkan tahniah..!!! Teruskan usahe ye.Yang penting Projek 1 kite nanti...
Meh Abang tolong kengkawan sume...!!!
Kepada sume kwan-kwan multimedia yang saye hormati...,
Question 3..
=============================================================
//NAME : ABANG DUIS BIN ABANG NEN
//MATRIC NO : 153026
//DATE : 10 SEPTEMBER 2009 (THURSDAY)
//TASK : QUESTION 3, ASSIGNMENT 4
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);
//Prompt the user to enter number of line
System.out.print("Enter the YEAR,eg,2009 : ");
int year = input.nextInt();
System.out.print(
"\n\n1 : JANUARY\n" +
"2 = FEBRUARY\n" +
"3 = MARCH\n" +
"4 = APRIL\n" +
"5 = MAY\n" +
"6 = JUNE\n" +
"7 = JULY\n" +
"8 = AUGUST\n" +
"9 = SEPTEMBER\n" +
"10= OCTOBER\n" +
"11= NOVEMBER\n" +
"12= DECEMBER\n\n");
//Prompt the user to enter the month
System.out.print("Enter the MONTH,refer the match above : ");
int month = input.nextInt();
//Declaration
String months = null;
int days = 0;
//Options
if (month==1){
months = "JANUARY";
days = 31;}
else if (month==2){
months = "FEBRUARY";
if (year%4!=0)
days = 28;
else
days = 29;}
else if (month==3){
months = "MARCH";
days = 31;}
else if (month==4){
months = "APRIL";
days = 30;}
else if (month==5){
months = "MAY";
days = 31;}
else if (month==6){
months = "JUNE";
days = 30;}
else if (month==7){
months = "JULY";
days = 31;}
else if (month==8){
months = "AUGUST";
days = 31;}
else if (month==9){
months = "SEPTEMBER";
days = 30;}
else if (month==10){
months = "OCTOBER";
days = 31;}
else if (month==11){
months = "NOVEMBER";
days = 30;}
else if(month==12){
months = "DECEMBER";
days = 31;}
else {
//If user enter the wrong input of value
System.out.print("\nWrite the true month between 1 to 12..\n");
System.exit(0);}
//Output or result
System.out.print("\nRESULT :\n" + months + " " + year + " has " + days + " days.\n");
}
}
===============================================================
Question 4..
//NAME : ABANG DUIS BIN ABANG NEN
//MATRIC NO : 153026
//DATE : 10 SEPTEMBER 2009 (THURSDAY)
//TASK : QUESTION 4, ASSIGNMENT 4
import java.util.Scanner;
public class Question4{
public static void main(String[] args){
//Create a Scanner
Scanner input = new Scanner(System.in);
//Prompt the user to enter number of line
System.out.print("Enter the number of lines : ");
int numberOfLines = input.nextInt();
//Estimate the line
if (numberOfLines <> 7) {
System.out.println("You must enter a number from 1 to 7");
System.exit(0);
}
// Print lines
for (int row = 0; row <= numberOfLines-1; row++) { // Print spaces for (int column = 2; column <= numberOfLines - row; column++) System.out.print(" "); // Print leading of numbers for (int num = row; num >= 0; num--){
double calc = Math.pow(2,num);
//Convert calc from double to integer
int calc2 = (int)calc;
//Print result
System.out.print((calc2 >= 10) ? " " + calc2 : " " + calc2);}
// Start a new line
System.out.println();
}
}
}
=============================================================
Question 5...
//NAME : ABANG DUIS BIN ABANG NEN
//MATRIC NO : 153026
//DATE : 10 SEPTEMBER 2009 (THURSDAY)
//TASK : QUESTION 5, ASSIGNMENT 4
import java.util.Scanner;
public class Question5{
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);
//Prompt the user to enter number of line
System.out.print("Enter the number of lines : ");
int numberOfLines = input.nextInt();
//Estimate the number of line
if (numberOfLines <> 10) {
System.out.println("You must enter a number from 1 to 10");
System.exit(0);
}
//Print lines
for (int row = 1; row <= numberOfLines; row++) { //Print spaces for (int space = 1; space <= numberOfLines-row; space++) System.out.print(" "); //Print leading of number for (int lead = 1; lead <= row;lead++ ){ double num = Math.pow(2,(lead-1)); int num2 = (int)num; System.out.print((num2 >= 10) ? " " + num2 : " " + num2);
}
//Print ending of number
for (int end = row-2; end >= 0; end--){
double num3 = Math.pow(2,(end));
int num4 = (int)num3;
System.out.print((num4 >= 10) ? " " + num4 : " " + num4);
}
// Start a new line
System.out.println();
}
}
}
====================================================



Tolong komen di bawah ye..
Mane2 antare menarik[/] dan hebat [/] sahaje..Terima kasih kerane melayari dan muat turun coding yang saye kongsikan ni..
SELAMAT BERPUASA SUME!!!
===========================
Hak cipta : ABANG DUIS (ABEY89)...
===========================
Bagus..Terima kasih
ReplyDelete