I would like to create a java prob that will request three integers from a users and have it printout the sum and product as such:


the 3 different integers are : 13, 27, 14.
the sum is 54
The product is 4914
Completed


Have i programm the right way:

import java.util.Scanner;

 public class Template
 {
 	public static void main(String[] args)
 	{
// display a welcome message
 	System.out.println("");

System.out.println(); //print a blank line

 	// get the input from the user
 	Scanner sc = new Scanner(System.in) ;
 	System.out.print("the 3 different integers are: 13, 27, 14");
 	double subtotal = sc.nextDouble();

 	// Calculate the discount amount and total
 	int num1 = 13;
 	int num2 = 27;


 	// format and display the result
 		String message = "The sum is: " + num1 + "\n"
 				+ "the product is:         " + num2 * "\n"
 	System.out.println(message);

 	}

 }

Thank you

No, because you hard-coded the values in, you never prompted the user. But you knew that. So what are you asking .. ?

No, because you hard-coded the values in, you never prompted the user. But you knew that. So what are you asking .. ?

Could you show me how to prompt to a user to enter three different values. so far i only found out how to prompt for only one number.

int num1=0;
int num2=0;
int num3=0;
int i=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(i<3)
{
	if(i==0)
	{
 num1 =Integer.parseInt(br.readLine());
	}
	if(i==1)
	{
 num2 =Integer.parseInt(br.readLine());
	}
	if(i==2)
	{
 num3 =Integer.parseInt(br.readLine());
	}
 i++;
}

System.out.println("The sum is: "+(num1+num2+num3)+"the product is" + (num2 *num1*num3));

you want prompt by GUI ..see messageDialoge in swing API

don't just feed him code ...
it's like the "give a man a fish, or teach him to catch 'm" principle..
he already knew how to prompt for one value ...
you could 've told him to put it in a loop. the code you gave him will allow him to prompt for three integers. what if he wants it to be more dynamic, and make the user decide each time how many integers there have to be.
are you going to give him that as well, or will you give him a pointer and let him learn?

and why the loop in your code?? it would do exactly the same, without the loop and those redundant if-statements


and why the loop in your code?? it would do exactly the same, without the loop and those redundant if-statements

Yeah you are right! loop or without loop it still does the same thing...

don't just feed him code ...
it's like the "give a man a fish, or teach him to catch 'm" principle..
he already knew how to prompt for one value ...
you could 've told him to put it in a loop. the code you gave him will allow him to prompt for three integers. what if he wants it to be more dynamic, and make the user decide each time how many integers there have to be.
are you going to give him that as well, or will you give him a pointer and let him learn?

and why the loop in your code?? it would do exactly the same, without the loop and those redundant if-statements

ok whats the problem...nothing...

the help he need for prompt i know it man...

that's why i refer swing api to him...

once again i didn't give fish instead of teach...

the only thing i said that what is the difference between frog and fish...

hello

Sorry, if i started any confusion.
What i am looking for is some guidance how to request three integer from the User. i figured out the arithemic but enable to output three integer on the same line.

hello

Sorry, if i started any confusion.
What i am looking for is some guidance how to request three integer from the User. i figured out the arithemic but enable to output three integer on the same line.

pk you want single line input like 12,23,45,33

then use bufferedreader(system.in );

and
string input=br.redaline();

and string iparr[]=use input.split (",");

if(iparr.length<5)
{
look showMessageDialog in swing api..to prompt the user
}

then add=intager.parseint(iparr[1])+..+

Here is what i have so far
what i want is the have all three integer line up on one line.
and look as: the 3 different integers are : 13, 27, 14

import java.util.Scanner;
public class Doc5
{
	public static void main (String[] args){

int num1, num2, num3, num4;
int [] data1;
data1 = new int[10];
System.out.println("\tOutput");
Scanner in1 = new Scanner(System.in);
num1 = in1.nextInt();num2 = in1.nextInt();num3 = in1.nextInt();

System.out.println(); //print a blank line

 	// Calculate the discount amount and total
 	int sum = + num1 + num2 + num3;
 	int multiplication = num1 * num2 * num3;


 	// format and display the result
 		String message =
 				 "The Sum is:       " + sum + "\n"
 				+ "The product:       " + multiplication + "\n";
 	System.out.println(message);
}
}

Here is what i have so far
what i want is the have all three integer line up on one line.
and look as: the 3 different integers are : 13, 27, 14

Use System.out.println() to do that. For example,

System.out.println("The three different integers are: " + int1 + " some more text here " + int2);

Try that out, see what it prints, then adapt that examples to your requirements. Also, you've probably already realized this, but ignore musthafa.

Thanks for your help
Finaly made it work
Here what i do:

import java.util.Scanner;
public class Lab11
{
	public static void main (String[] args){

		// create a Scanner object
		Scanner sc = new Scanner(System.in);


// read three int values
System.out.print("Enter three integer values:  ");
int i1 = sc.nextInt();
int i2 = sc.nextInt();
int i3 = sc.nextInt();


// Calculate the average and display the result
int sum = i1 +i2 +i3;
int product = i1 *i2 *i3;
System.out.println("Average: " + sum);
System.out.println("the product is " + product);
System.out.println("Complete");

}
	}

Glad you got it to work, mark the thread as solved

..... but ignore musthafa.

don't forget me..:)

The three different integers are

the 3 different integers are : 13, 27, 14

System.out.println("the 3 different integers are : "+num1+","+num2+","+num3);


In case you are looking for just formatting your output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.