1. Write a while loop that displays all even numbers till 40.
find the factorial yalue of any number entered
Answers
Answer:
1.
import java.util.Scanner;
public class DisplayEvenNumbersExample3
{
public static void main(String[] args)
{
int number, i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the limit: ");
number = sc.nextInt();
i=2;
System.out.print("Lit of even numbers: ");
//the while loop executes until the condition become false
while(i<=number)
{
//prints the even number
System.out.print(i +" ");
//increments the variable i by 2
i=i+2;
}
}
}
2.
import java.util.Scanner;
import java.util.Scanner;class Factorial
import java.util.Scanner;class Factorial{
import java.util.Scanner;class Factorial{ public static void main(String args[])
import java.util.Scanner;class Factorial{ public static void main(String args[]) {
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1;
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial");
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in);
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt();
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0)
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative.");
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else {
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++)
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) f = f*c;
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) f = f*c; System.out.println("Factorial of "+n+" is = "+f);
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) f = f*c; System.out.println("Factorial of "+n+" is = "+f); }
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) f = f*c; System.out.println("Factorial of "+n+" is = "+f); } }
import java.util.Scanner;class Factorial{ public static void main(String args[]) { int n, c, f = 1; System.out.println("Enter an integer to calculate its factorial"); Scanner in = new Scanner(System.in); n = in.nextInt(); if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) f = f*c; System.out.println("Factorial of "+n+" is = "+f); } }}
Answer:
it is with for loop also you can recommend mine also