GeekInterview.com
Series: Subject: Topic:
Question: 18 of 1118

Write a program that prompts the user to input three numbers.

The program should then output numbers in ascending order.
Asked by: qwerty0605 | Member Since Jan-2012 | Asked on: Jan 15th, 2012

View all questions by qwerty0605

Showing Answers 1 - 3 of 3 Answers
Rashmi

Answered On : Jan 22nd, 2012

Code
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class ((class name here)) {
  5.  
  6. public static void main(String[] args) {
  7. Scanner q=new Scanner(System.in);
  8. System.out.println("Input three numbers");
  9. int i[] = new int[3];
  10. i[0]=q.nextInt();
  11. i[1]=q.nextInt();
  12. i[2]=q.nextInt();
  13. Arrays.sort(i);
  14. System.out.println(i[0]+","+i[1]+","+i[2
  15. }
  16.  
  17. }

  
Login to rate this answer.
NARESH KUMAR

Answered On : Feb 3rd, 2012

Code syntax is:-

Code
  1.  
  2. import java.util.Scanner;
  3. public class A{
  4.  
  5. public static void main(String[] args){
  6. Scanner scanner=new Scanner (System.in);
  7. int v1=s.nextInt();//value 1st
  8. int v2=s.nextint();//value 2nd
  9. int v3=s.nextInt();//value 3rd
  10. }//end of main method
  11. }// end of class

  
Login to rate this answer.
vishnu

Answered On : Feb 24th, 2012


import java.util.Iterator;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;


public class ascend {

static int i=0;
public static void main(String[] args)
{
SortedSet elements = new TreeSet();
for(int j=0;j<3;j++)
{
Scanner sc=new Scanner(System.in);
i=sc.nextInt();
elements.add(i);
}
Iterator iter = elements.iterator();
while (iter.hasNext()) {
System.out.println("Element in set is --> "+iter.next());
}}}

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.