Three Solved Problems
2 posters
Page 1 of 1
Three Solved Problems
1. Write a program that will reverse a string .String Reverse
- Code:
import java.util.Scanner;
public class StringReverse {
static Scanner scr = new Scanner(System.in);
public static String Reverse(String t) {
String string = "";
for (int i = t.length() - 1; i >= 0; i--) {
string += t.charAt(i);
}
return string;
}
public static void main(String[] args) {
System.out.println("Enter your String: ");
String str = scr.next();
System.out.println("Your Reverse String is: " + Reverse(str));
}
}
- Code:
import java.util.Scanner;
public class Fibonacci {
static Scanner scr = new Scanner(System.in);
static int num;
public static int fib(int n) {
if (n < 2)
return n;
else
return fib(n - 1) + fib(n - 2);
}
public static void main(String[] args) {
System.out.println("koto projonta chao...?");
num = scr.nextInt();
for (int i = 1; i <= num; i++)
System.out.print(fib(i) + ", ");
}
}
- Code:
import java.util.Scanner;
public class Factorial {
static Scanner scr = new Scanner(System.in);
public static long factorial(int n) {
if (n <= 1)
return 1;
else
return (n * factorial(n - 1));
}
public static void main(String[] args) {
int num;
System.out.print("enter your number..?");
num = scr.nextInt();
System.out.print("your factorial: " + factorial(num));
}
}
Similar topics
» ACM-Problems Set Collection
» Bash Script Assignmet (Solved)
» 10 pattern type problems
» Text Copy Problem in Ubuntu from closed window : Solved!
» QA Assignment 2: Phase 1 - Requirement Analysis - Solved by Erfana Madam
» Bash Script Assignmet (Solved)
» 10 pattern type problems
» Text Copy Problem in Ubuntu from closed window : Solved!
» QA Assignment 2: Phase 1 - Requirement Analysis - Solved by Erfana Madam
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford