Computer Science, asked by souviksen779, 7 months ago

Write a java program to pass an integer as argument and print the second largest digit.​

Answers

Answered by June021
1

Answer:

import java.util.*;

class Main{

public static void main(String args[]){

int a[]=new int[100];

System.out.println("enter array length:");

Scanner sc=new Scanner();

n=sc.nextInt();

for(int i=0;i<n;i++)

{

a[i]=sc.nextInt();

}

int largest=a[0];

for(int i=0; i<n;i++)

{

if(largest<a[i])

{

largest=a[i];

}

}

int secondlar=a[0];

for(int i=0;i<n;i++)

{

if((secondlar<largest)&&(secondlar>a[i]))

{

secondlar=a[i];

}

}

System.out.println(secondlar);

}

}

Explanation:

I hope you get it.

Please mark as brainliest accordingly.

Answered by CopyThat
2

Program: {JAVA}

public class Brainly

{

static void main(int n)

{

int d,s=0,l=0,f=0,sl=0,t=n;

while(n!=0)

{

d=n%10;

if(f==0)

{

l=d;

f=1;

}

if (d>l)

l=d;

n=n/10;

}

f=0;

while(t!=0)

{

d=t%10;

if(d!=l)

{

if(f==0)

{

sl=d;

f=1;

}

if(d>sl)

sl=d;

}

t=t/10;

}

System.out.println("Second Largest digit="+sl);

}

}

Similar questions