sid's
Would you like to react to this message? Create an account in a few clicks or log in to continue.

sid's

OPen Discussion
 
HomePortalSearchLatest imagesRegisterLog in

 

 PROGRAMMING EXAMPLE..

Go down 
AuthorMessage
Admin
Admin



Posts : 50
Join date : 2007-08-10
Age : 44
Location : Kuala Lumpur

PROGRAMMING EXAMPLE.. Empty
PostSubject: PROGRAMMING EXAMPLE..   PROGRAMMING EXAMPLE.. Icon_minitimeFri Sep 14, 2007 12:12 pm

Arrow ok..here are some examples that will help you out..!!

import javax.swing.*;

public class EnterNumbers {

public static void main(String[] args){

String input, outMessage;
int maxNum,count;
double num=0,sum=0;


input = JOptionPane.showInputDialog("How many numbers do you want to enter?");
maxNum= Integer.parseInt(input);

outMessage = "This program will ask you to enter " +maxNum +" numbers";


JOptionPane.showMessageDialog(null,outMessage,"Numbers",
JOptionPane.INFORMATION_MESSAGE);

count = 1;

while (count<=maxNum){

input = JOptionPane.showInputDialog("Enter number " + count + ":");
num= Double.parseDouble(input);

JOptionPane.showMessageDialog(null,"The number entered is " + num,"Numbers",
JOptionPane.INFORMATION_MESSAGE);
sum=sum+num;

count++;
}

JOptionPane.showMessageDialog(null,"The total of "+maxNum+" numbers entered is : " + sum,"Numbers",
JOptionPane.INFORMATION_MESSAGE);
System.out.println(sum);



System.exit(0);
}//end of main
}//end of class
Back to top Go down
https://sidnazuha.board-directory.net
Admin
Admin



Posts : 50
Join date : 2007-08-10
Age : 44
Location : Kuala Lumpur

PROGRAMMING EXAMPLE.. Empty
PostSubject: NESTED FOR   PROGRAMMING EXAMPLE.. Icon_minitimeFri Sep 14, 2007 12:13 pm

Exclamation Nested for, try to figure out how it works..

public class NestedFor1 {

public static void main(String[] args){

for(int x=0; x<4; x++){
for(int y= x ;y<4; y++){
System.out.print("*");
}
System.out.println();
}

}
}
Back to top Go down
https://sidnazuha.board-directory.net
Admin
Admin



Posts : 50
Join date : 2007-08-10
Age : 44
Location : Kuala Lumpur

PROGRAMMING EXAMPLE.. Empty
PostSubject: Formatted out..   PROGRAMMING EXAMPLE.. Icon_minitimeFri Sep 14, 2007 12:16 pm

bounce useful examples to format ur output..

Arrow eg1:
import java.text.DecimalFormat;

/**
This program demonstrates the DecimalFormat class.
*/

public class Format3
{
public static void main(String[] args)
{
double number1 = 123.899;
double number2 = 1233.899;
double number3 = 12345.899;
double number4 = 123456.899;
double number5 = 1234567.899;

// Create a DecimalFormat object.
DecimalFormat formatter = new DecimalFormat("#,##0.00");

// Display the formatted variable contents.
System.out.println(formatter.format(number1));
System.out.println(formatter.format(number2));
System.out.println(formatter.format(number3));
System.out.println(formatter.format(number4));
System.out.println(formatter.format(number5));
}
}


Arrow eg2:import java.text.DecimalFormat;

/**
This program demonstrates the DecimalFormat class.
*/

public class Format2
{
public static void main(String[] args)
{
double number1 = 0.166666666666667;
double number2 = 1.666666666666667;
double number3 = 16.666666666666667;
double number4 = 166.666666666666667;

// Create a DecimalFormat object.
DecimalFormat formatter = new DecimalFormat("000.00");

// Display the formatted variable contents.
System.out.println(formatter.format(number1));
System.out.println(formatter.format(number2));
System.out.println(formatter.format(number3));
System.out.println(formatter.format(number4));
}
}
Back to top Go down
https://sidnazuha.board-directory.net
Sponsored content





PROGRAMMING EXAMPLE.. Empty
PostSubject: Re: PROGRAMMING EXAMPLE..   PROGRAMMING EXAMPLE.. Icon_minitime

Back to top Go down
 
PROGRAMMING EXAMPLE..
Back to top 
Page 1 of 1
 Similar topics
-
» Programming Example
» Task 1 : Example of programming languages

Permissions in this forum:You cannot reply to topics in this forum
sid's :: TEACHING MATERIAL :: UPM-SAK3100-
Jump to: