0% found this document useful (0 votes)
14 views3 pages

Combined Files

Uploaded by

suhanthy2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Combined Files

Uploaded by

suhanthy2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// File: Combinations_4.

java

import java.util.*;
public class Combinations_4 {
static int Count = 0;
public static void getPermutations(int[] array){
helper(array, 0);
}
private static void helper(int[] array, int pos){
if(pos >= array.length - 1){
System.out.print("⌈");
for(int i = 0; i < array.length - 1; i++){
System.out.print(array[i] + ", ");
}
if(array.length > 0)
System.out.print(array[array.length - 1]);
System.out.println("⌋");
Count++;
return;
}
for(int i = pos; i < array.length; i++){

int t = array[pos];
array[pos] = array[i];
array[i] = t;

helper(array, pos+1);

t = array[pos];
array[pos] = array[i];
array[i] = t;
}
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int not = in.nextInt();
int[] numbers = new int[not];
int n=1;
if(not == 5) {
for (int i=0;i<not;i++){
numbers[i] = n;
n++;
}
}
else if (not == 4) {
for (int i=0;i<not;i++){
numbers[i] = n;
n++;
}
}
else if (not == 3) {
for (int i=0;i<not;i++){
numbers[i] = n;
n++;;
}
}
else if (not == 2) {
for (int i=0;i<not;i++){
numbers[i] = n;
n++;
}
}
else if (not ==1) {
for (int i=0;i<not;i++){
numbers[i] = n;
n++;
}
}
else if(not >5) {
System.out.print("not more than 5!");
System.exit(0);
}
getPermutations(numbers);
System.out.print(Count);
}
}

// File: LuckyNumber_2.java

import java.util.*;
public class LuckyNumber_2 {
Scanner in = new Scanner(System.in);
int n, n1, n2, m = 0, p;
void input() {
System.out.print("Enter a number: ");
n = in.nextInt();
n1 = n2 = n;
}
void calculate() {
while (n2!=0) {
n1 = n2%10;
n2 = n2/10;
m = m + n1;
}
if (m>1) {
n1 = n2 = m;
while (n2!=m) {
n1 = n1%10;
n2 = n2/10;
p = p+n1;
}
}
else if (m < 1) {
System.out.println("Error");
}
if (p==1 || m ==1){
System.out.println("Number is a Lucky Number??");
}
else {
System.out.println("Number is not a Lucky Number🥲🥲🥲🥲🥲🥲🥲?");
}
}
public static void main() {
LuckyNumber_2 obj = new LuckyNumber_2();
obj.input();
obj.calculate();
}
}
// File: TimeToWords_1.java

import java.util.*;
public class TimeToWords_1 {
static String[] hours = { //list of hours
"Twelve", "One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Eleven"
};
static String[] minutes = { // minutes
"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Quarter",
"Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Twenty One",
"Twenty Two", "Twenty Three", "Twenty Four", "Twenty Five", "Twenty Six",
"Twenty Seven", "Twenty Eight", "Twenty Nine"
};

static String timeInWords(int h, int m) { //convert number input to Time in


words
String time = "";

if (m == 0) {
time = hours[h] + " o' clock";
} else if (m == 15) {
time = "Quarter past " + hours[h];
} else if (m == 30) {
time = "Half past " + hours[h];
} else if (m == 45) {
time = "Quarter to " + hours[(h + 1) % 12];
} else if (m <= 30) {
time = minutes[m] + " minutes past " + hours[h];
} else {
time = minutes[60 - m] + " minutes to " + hours[(h + 1) % 12];
}

return time;
}

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


Scanner scanner = new Scanner(System.in);
System.out.print("Enter hour (1-12): ");
int hour = scanner.nextInt();
System.out.print("Enter minute (0-59): ");
int minute = scanner.nextInt();

if (hour < 1 || hour > 12 || minute < 0 || minute > 59) {


System.out.println("Invalid input. Please enter valid hour and
minute.");
} else {
String timeInWords = timeInWords(hour, minute);
System.out.println("Time in words: " + timeInWords);
}

You might also like