Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication85;
- import java.util.Scanner;
- /**
- *
- * @author Student
- */
- public class JavaApplication85 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner scan =new Scanner(System.in);
- System.out.println("Menu");
- System.out.println("[1] Swap and Set");
- System.out.println("[2] Fibonacci");
- System.out.println("[3] Factorial");
- System.out.print("Choose: ");
- int a=scan.nextInt();
- if (a==1) {
- System.out.println("Swap and Sort");
- System.out.println(" ");
- int x,y,temp;
- System.out.print("Num 1: ");
- x=scan.nextInt();
- System.out.print("Num 2: ");
- y=scan.nextInt();
- //swapping
- temp=x;
- x=y;
- y=temp;
- //output
- System.out.println("Swapped numbers:");
- System.out.println("Num 1: "+x);
- System.out.println("Num 2: "+y);
- }
- else if (a==2) {
- System.out.println("Fibonacci");
- System.out.print("Num 1: ");
- int n1=scan.nextInt();
- System.out.print("Num 2: ");
- int n2=scan.nextInt();
- int temp =0;
- for (int i=1;i<=10;i++){
- temp=n1+n2;
- n1=n2;
- n2=temp;
- System.out.println(n2);}
- }
- else if (a==3) {
- int n,c,fact=1;
- System.out.println("Factorial");
- System.out.print("Enter number: ");
- n=scan.nextInt();
- if (n<0)
- System.out.println("Number should be non-negative!");
- else
- {
- for (c=1;c<=n;c++)
- fact=fact*c;
- System.out.println("Factorial: "+fact);
- }
- }
- else {
- System.out.println("Please choose the right value.");}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement