OOP-JAVA Practical 5
- Aim: Write a program that prompts the user to enter three integers and display the integers in decreasing order.
- Code:
import java.util.Scanner; public class practical5 { public static void main(String args[]){ int num[] =new int[3],i,j; Scanner a=new Scanner(System.in); System.out.println("Enter 3 numbers:"); for(i=0;i<3;i++){ num[i]=a.nextInt(); } for(i=0;i<3;i++){ for(j=i+1;j<3;j++){ if(num[i]<num[j]){ int temp; temp=num[i]; num[i]=num[j]; num[j]=temp; } } } System.out.println("Numbers in decreasing order:"); for(i=0;i<3;i++){ System.out.print(+num[i]+" "); } } }
- Output:
Comments
Post a Comment