Question

Write a Java program that reads 10 integers from the keyboard and outputs all the pairs...

Write a Java program that reads 10 integers from the keyboard and outputs all the pairs whose sum is 30 .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

PrintPairOfThirty.java

package classes13;

import java.util.Scanner;

public class PrintPairOfThirty {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int numbers[] = new int[10];
       System.out.println("Enter 10 numbers below");
       for(int i=0;i<10;i++){
           numbers[i] = sc.nextInt();
       }
       System.out.println(" Pair with sum 30 are as below ");
       for(int i=0;i<10;i++){
           for(int j=i+1;j<10;j++){
               if(numbers[i]+numbers[j]==30){
                   System.out.println("("+numbers[i]+","+numbers[j]+")");
               }
           }  
       }
   }
}

output:

Add a comment
Know the answer?
Add Answer to:
Write a Java program that reads 10 integers from the keyboard and outputs all the pairs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT