Computer Science, asked by akshad52, 1 year ago

how to print factors of 6 using switch case in java

Answers

Answered by Anonymous
4

CODE :-


import java.util.*;

class factors_of_six

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter 1 to see the factors of 6 ");

int n=sc.nextInt();

switch(n)

{

case 1:

System.out.println("Here are the factors :");

for(int i=1;i<=6;i++)

{

if(6%i==0)

System.out.println(i);

}

default:

System.out.println("Invalid choice");

}

}

}//end of class


----------------------------------------------------------------------

OUTPUT :

Enter 1 to see the factors of 6

Here are the factors :

1

2

3

6


=================================================


Hope it helps !

_________________________________________________________

Answered by Arein22
1

for(n=1;N<=6;n++)

{

if(n%6==0)

{

Sopln(n);

}

}

Answer:

1

2

3

6


Similar questions