CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2888|Reply: 6

sapa tau java nak minta tlg

[Copy link]
Post time 15-7-2007 04:01 PM | Show all posts |Read mode
import java.util.Scanner;

public class Addition
{
  public static void main(String args[])
  {

    Scanner input = new Scanner(System.in);
   
    double number1;
    double number2;
    double sum;

    System.out.print("enter first integer: ");
    number1=input.nextInt();
   
    System.out.print("enter second integer: ");
    number2= input.nextInt();

    sum=number1+number2;
   
    System.out.printf("Sum is %d\n",sum/2);
   }
}

kwn aku mailkn kat forum ni..ade sape2 tau java?
kwn aku tanye nape output x leh kuar walaupun da letak double..kalu bole die nak output tuh kuar dlm decimal
Reply

Use magic Report


ADVERTISEMENT


Post time 15-7-2007 10:30 PM | Show all posts
import java.util.Scanner;

public class Addition
{
  public static void main(String args[])
  {
    Scanner input = new Scanner(System.in);

    int number1,number2;
   
    System.out.print("enter first integer: ");
    number1=input.nextInt();
   
    System.out.print("enter second integer: ");
    number2= input.nextInt();

    int sum;
    sum=number1+number2;
   
    System.out.printf("Sum is "+sum);
   }
}

Rate

1

View Rating Log

Reply

Use magic Report

Post time 16-7-2007 12:17 AM | Show all posts
Betul maksud orang_letrik. Kalau nama class Addition dan objektif nak buat addition kenapa bahagi 2?

Other than that,

System.out.printf("Sum is %d\n",sum/2);


error sebab format specifier %d tak compatible dgn argument sum/2 sebab %d expects integer tapi argument sum/2 memulangkan nilai floating points atau double.

Tukar %d kepada %f will do the job.

Rate

1

View Rating Log

Reply

Use magic Report

 Author| Post time 17-7-2007 01:25 PM | Show all posts
oooowh tq tq...
Reply

Use magic Report

Post time 7-8-2007 02:05 PM | Show all posts
hulaaa mintak tolong sikit
lec aku suruh buat lab work, guna java.. dia suruh buat satu program yang boleh bagi tahu user umur dia bila dia masukkan tahun dia lahir.. sebenarnya aku boleh buat dia isi tahun sekarang dan tahun dia lahir.. lepas tu tolak je..

tapi aku nak buat tahun sekarang, dia tak payah isi.. automatik di ambil dari windows time punya tahun.. ada cara tak?? dateline 12082007..

kalau tak aku buat cara biasa la
Reply

Use magic Report

Post time 7-8-2007 02:07 PM | Show all posts
la guna la aje java date
Reply

Use magic Report

Follow Us
Post time 7-8-2007 02:12 PM | Show all posts
kalau instantiate a new date object, dia akan ambik current windows date, kalau tak silap saya la...

import java.util.Date;

...

Date today_date = new Date();  // ni date for today
Date birth_date = ... ;

dan seterusnya...


harap dapat membantu
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

27-12-2024 02:16 PM GMT+8 , Processed in 0.068861 second(s), 25 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list