how to get the correct difference and product of dis?!

import java.io.*;

public class exer05{
	public static void main(String args[])throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int num = 0;
		int number = 0;
		int diff = 0,pro = 0,sum=0;
		
	
	
		System.out.print("Enter number of times:");
		number = Integer.parseInt(br.readLine());
		
			
		for(int i=1;i<=number;i++){
		
		 System.out.print("Number ("+ number +")");
		 num = Integer.parseInt(br.readLine());
		 
		 diff = diff - num;
		 pro =  pro * num;}
		 {
		 
		 System.out.println("\nDiff: "+diff);
		 System.out.println("Pro: "+pro);}
		 
		 
		
			
			
		
	}
}

Recommended Answers

All 3 Replies

fixed couple of things:
cycle indention was off, diff and pro was printed on only last number because of the way you organized the brackets. heres the reworked version

import java.io.*;

public class exer05{
	public static void main(String args[])throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int num = 0;
		int number = 0;
		int diff = 0,pro = 1,sum=0; 

		System.out.print("Enter number of times:");
		number = Integer.parseInt(br.readLine());

		for(int i=0;i<number;i++){ //has to be total -1		
			 System.out.println("Number ("+ (i+1) +")"); //current index
			 num = Integer.parseInt(br.readLine());
			 
			 diff = diff - num;
			 pro =  pro * num;
	
			 System.out.println("Diff: "+diff);
			 System.out.println("Pro: "+pro);
		}
	}
}

I am not very much clear what you're trying to ask. Whose difference and product you want to find out. It would be good if you explain what your requirement is in more detail.

To the OP:
It would be better that you chose a better thread title in future, a title like "need help.." is useless, because pretty much everyone which opens a thread here needs help.
Try to be more descriptive the next time.

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.