public static void main(String[] args)
{
// input
Scanner kb=new Scanner(in);
// input 2 doubles
double num1=kb.nextDouble();
double num2=kb.nextDouble();
// sum
out.println(num1+num2);
// difference
out.println(num1-num2);
// product
out.println(num1*num2);
// quotient
out.println(num1/num2);
}
could someone help me create a source code that requires you to enter 2 numbers then gets the sum, difference, product and quotient of them after entering
3 answers
If you use the Scanner class, you would have to import the java.util.Scanner class before your first use.
You can use the Scanner class to get input by creating an instance
Scanner sc=new Scanner(System.in);
which will use the console input for your data.
To print (without carriage return), you could use
System.out.print("string/message");
To print with carriage return, you could use:
System.out.println(""+data +"messages");
Integer data will be converted to Sting and concantenated with any String data.
you need to define the integer variables using
int k1,k2;
and input using the Scanner class, for example:
k1=sc.nextInt();
This resumes much of the commands you will need. Use the Java API to help you with syntax, and post your rough copy if you need more help.
You can use the Scanner class to get input by creating an instance
Scanner sc=new Scanner(System.in);
which will use the console input for your data.
To print (without carriage return), you could use
System.out.print("string/message");
To print with carriage return, you could use:
System.out.println(""+data +"messages");
Integer data will be converted to Sting and concantenated with any String data.
you need to define the integer variables using
int k1,k2;
and input using the Scanner class, for example:
k1=sc.nextInt();
This resumes much of the commands you will need. Use the Java API to help you with syntax, and post your rough copy if you need more help.
In case you don't have the Java API installed, it can be found at the following link:
http://java.sun.com/javase/6/docs/api/
http://java.sun.com/javase/6/docs/api/