Computer Science, asked by MariaDanica, 1 month ago

write a program to input a number and print its multiplication table of 20 or Check if the number is prime or not​

Answers

Answered by deepakkumar9254
2

Programs using java :-

i.) Write a program to input a number and print its multiplication table of 20.

import java.util.Scanner; //importing package

class asc //class declaration  

{

   public static void main (String args[]) //main()method declaration

   {

       Scanner sc = new Scanner(System.in); //input object creation

       System.out.println("Enter a number");

       int n = sc.nextInt();  

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

       {

           int a = n * i;

           System.out.println(a);

       }

   }

}

Output :- in the attachment

Glossary :-

\begin{array}{| c | c | c |}\cline{1-3} \bf variable &amp; \bf Type &amp; \bf Description\\ \cline{1-3} n &amp;\sf int &amp; to\:\:store\:\:a\:\:number \\ \cline{1-3} i &amp;\sf int &amp; to\:\:run\:\:the\:\:l{o}{o}p\:\:20\:\:times\\ \cline{1-3} a &amp;\sf int &amp; to\:\:store\:\:the\:\:multiplication\:\:table \\ \cline{1-3}\end{array}

ii.) Check if the number is prime or not​

import java.util.Scanner; //importing package

class prime //class declaration

{

   public static void main(String args[]) //main()method declaration

   {

       System.out.println("Enter a no.");

       Scanner sc=new Scanner(System.in); //input object creation

       int c=0, i, a; //variable declaration

       a = sc.nextInt();

       for (i=1;i<=a;i++)

       {

           if(a%i==0)

           c++;

       }

       if(c==2)

       {

           System.out.println("Prime");

       }

       else

       {

           System.out.println("Not prime");

       }

   }

}

Output :- in the attachment

Glossary :-

\begin{array}{| c | c | c |}\cline{1-3} \bf variable &amp; \bf Type &amp; \bf Description\\ \cline{1-3} a &amp;\sf int &amp; to\:\:store\:\:a\:\:number \\ \cline{1-3} i &amp;\sf int &amp; to\:\:run\:\:the\:\:l{o}{o}p\\ \cline{1-3} c &amp;\sf int &amp; to\:\:store\:\:the\:\:number\:\:of\:\:counts\\ \cline{1-3}\end{array}

Attachments:
Similar questions