Birthdaydate.java
import java.util.Scanner;
public class Birthdaydate {
public static void main(String[] args) {
//Declaring variables
char ch,ch1,ch2,ch3,ch4,ch5;
//Declaring each card as an 2-Dimensional Array
int card1[][]={{1,3,5,7},{9,11,13,15},{17,19,21,23},{25,27,29,31}};
int card2[][]={{2,3,6,7},{10,11,14,15},{18,19,22,23},{26,27,30,31}};
int card3[][]={{4,5,6,7},{12,13,14,15},{20,21,22,23},{28,29,30,31}};
int card4[][]={{8,9,10,11},{12,13,14,15},{24,25,26,27},{28,29,30,31}};
int card5[][]={{16,17,18,19},{20,21,22,23},{24,25,26,27},{28,29,30,31}};
//Scanner Object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continue to execute until user enters \'Y\' or \'y\'
do
{
//Declaring variable
int sum=0;
//Displaying card1 using nested for loop
System.out.println(\":: Card1 ::\");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf(\"%3d\",card1[i][j]);
}
System.out.println(\" \");
}
//Prompting whether the day of birth is having in card1 or not.
System.out.print(\"Do card#1 is having Your Birthday (Y/N):\");
ch1 = sc.next(\".\").charAt(0);
//If the day is in card 1,add the first row first column element to sum
if(ch1==\'Y\' || ch1==\'y\')
sum+=card1[0][0];
//Displaying card2 using nested for loop
System.out.println(\":: Card2 ::\");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf(\"%3d\",card2[i][j]);
}
System.out.println(\" \");
}
//Prompting whether the day of birth is having in card2 or not.
System.out.print(\"Do card#2 is having Your Birthday (Y/N):\");
ch2 = sc.next(\".\").charAt(0);
//If the day is in card 2,add the first row first column element to sum
if(ch2==\'Y\' || ch2==\'y\')
sum+=card2[0][0];
//Displaying card3 using nested for loop
System.out.println(\":: Card3 ::\");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf(\"%3d\",card3[i][j]);
}
System.out.println(\" \");
}
//Prompting whether the day of birth is having in card3 or not.
System.out.print(\"Do card#3 is having Your Birthday (Y/N):\");
ch3 = sc.next(\".\").charAt(0);
//If the day is in card 3,add the first row first column element to sum
if(ch3==\'Y\' || ch3==\'y\')
sum+=card3[0][0];
//Displaying card4 using nested for loop
System.out.println(\":: Card4 ::\");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf(\"%3d\",card4[i][j]);
}
System.out.println(\" \");
}
//Prompting whether the day of birth is having in card4 or not.
System.out.print(\"Do card#4 is having Your Birthday (Y/N):\");
ch4 = sc.next(\".\").charAt(0);
//If the day is in card 4,add the first row first column element to sum
if(ch4==\'Y\' || ch4==\'y\')
sum+=card4[0][0];
//Displaying card5 using nested for loop
System.out.println(\":: Card5 ::\");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf(\"%3d\",card5[i][j]);
}
System.out.println(\" \");
}
//Prompting whether the day of birth is having in card5 or not.
System.out.print(\"Do card#5 is having Your Birthday (Y/N):\");
ch5 = sc.next.
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
Birthdaydate.javaimport java.util.Scanner;public class Birthdayd.pdf
1. Birthdaydate.java
import java.util.Scanner;
public class Birthdaydate {
public static void main(String[] args) {
//Declaring variables
char ch,ch1,ch2,ch3,ch4,ch5;
//Declaring each card as an 2-Dimensional Array
int card1[][]={{1,3,5,7},{9,11,13,15},{17,19,21,23},{25,27,29,31}};
int card2[][]={{2,3,6,7},{10,11,14,15},{18,19,22,23},{26,27,30,31}};
int card3[][]={{4,5,6,7},{12,13,14,15},{20,21,22,23},{28,29,30,31}};
int card4[][]={{8,9,10,11},{12,13,14,15},{24,25,26,27},{28,29,30,31}};
int card5[][]={{16,17,18,19},{20,21,22,23},{24,25,26,27},{28,29,30,31}};
//Scanner Object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continue to execute until user enters 'Y' or 'y'
do
{
//Declaring variable
int sum=0;
//Displaying card1 using nested for loop
System.out.println(":: Card1 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card1[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card1 or not.
2. System.out.print("Do card#1 is having Your Birthday (Y/N):");
ch1 = sc.next(".").charAt(0);
//If the day is in card 1,add the first row first column element to sum
if(ch1=='Y' || ch1=='y')
sum+=card1[0][0];
//Displaying card2 using nested for loop
System.out.println(":: Card2 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card2[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card2 or not.
System.out.print("Do card#2 is having Your Birthday (Y/N):");
ch2 = sc.next(".").charAt(0);
//If the day is in card 2,add the first row first column element to sum
if(ch2=='Y' || ch2=='y')
sum+=card2[0][0];
//Displaying card3 using nested for loop
System.out.println(":: Card3 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card3[i][j]);
}
System.out.println(" ");
}
3. //Prompting whether the day of birth is having in card3 or not.
System.out.print("Do card#3 is having Your Birthday (Y/N):");
ch3 = sc.next(".").charAt(0);
//If the day is in card 3,add the first row first column element to sum
if(ch3=='Y' || ch3=='y')
sum+=card3[0][0];
//Displaying card4 using nested for loop
System.out.println(":: Card4 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card4[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card4 or not.
System.out.print("Do card#4 is having Your Birthday (Y/N):");
ch4 = sc.next(".").charAt(0);
//If the day is in card 4,add the first row first column element to sum
if(ch4=='Y' || ch4=='y')
sum+=card4[0][0];
//Displaying card5 using nested for loop
System.out.println(":: Card5 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card5[i][j]);
}
System.out.println(" ");
4. }
//Prompting whether the day of birth is having in card5 or not.
System.out.print("Do card#5 is having Your Birthday (Y/N):");
ch5 = sc.next(".").charAt(0);
//If the day is in card 5,add the first row first column element to sum
if(ch5=='Y' || ch5=='y')
sum+=card5[0][0];
System.out.println("Your Birthday is "+sum);
System.out.print(" Do You want to continue? (y/n): ");
ch = sc.next(".").charAt(0);
System.out.println("________________________________");
}while(ch=='Y' || ch=='y');
}
}
_________________________________________________
Output:
:: Card1 ::
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
Do card#1 is having Your Birthday (Y/N):y
:: Card2 ::
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
Do card#2 is having Your Birthday (Y/N):y
:: Card3 ::
4 5 6 7
12 13 14 15
20 21 22 23
5. 28 29 30 31
Do card#3 is having Your Birthday (Y/N):n
:: Card4 ::
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Do card#4 is having Your Birthday (Y/N):n
:: Card5 ::
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Do card#5 is having Your Birthday (Y/N):n
Your Birthday is 3
Do You want to continue? (y/n):
y
:: Card1 ::
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
Do card#1 is having Your Birthday (Y/N):n
:: Card2 ::
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
Do card#2 is having Your Birthday (Y/N):y
:: Card3 ::
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
Do card#3 is having Your Birthday (Y/N):n
:: Card4 ::
6. 8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Do card#4 is having Your Birthday (Y/N):n
:: Card5 ::
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Do card#5 is having Your Birthday (Y/N):n
Your Birthday is 2
Do You want to continue? (y/n):
n
______________________________________________________
The reason this works because we are having the numbers of first row first column of cards as 1
2 4 8 16.With these 5 numbers we can amke any day between 1 and 31.Based on the Birthday
present in the cards those corresponding first row first column of every card is getting added to
find the birthday of the user.
______________________________________________________Thank you
Solution
Birthdaydate.java
import java.util.Scanner;
public class Birthdaydate {
public static void main(String[] args) {
//Declaring variables
char ch,ch1,ch2,ch3,ch4,ch5;
//Declaring each card as an 2-Dimensional Array
int card1[][]={{1,3,5,7},{9,11,13,15},{17,19,21,23},{25,27,29,31}};
int card2[][]={{2,3,6,7},{10,11,14,15},{18,19,22,23},{26,27,30,31}};
int card3[][]={{4,5,6,7},{12,13,14,15},{20,21,22,23},{28,29,30,31}};
int card4[][]={{8,9,10,11},{12,13,14,15},{24,25,26,27},{28,29,30,31}};
int card5[][]={{16,17,18,19},{20,21,22,23},{24,25,26,27},{28,29,30,31}};
7. //Scanner Object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
//This loop continue to execute until user enters 'Y' or 'y'
do
{
//Declaring variable
int sum=0;
//Displaying card1 using nested for loop
System.out.println(":: Card1 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card1[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card1 or not.
System.out.print("Do card#1 is having Your Birthday (Y/N):");
ch1 = sc.next(".").charAt(0);
//If the day is in card 1,add the first row first column element to sum
if(ch1=='Y' || ch1=='y')
sum+=card1[0][0];
//Displaying card2 using nested for loop
System.out.println(":: Card2 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card2[i][j]);
8. }
System.out.println(" ");
}
//Prompting whether the day of birth is having in card2 or not.
System.out.print("Do card#2 is having Your Birthday (Y/N):");
ch2 = sc.next(".").charAt(0);
//If the day is in card 2,add the first row first column element to sum
if(ch2=='Y' || ch2=='y')
sum+=card2[0][0];
//Displaying card3 using nested for loop
System.out.println(":: Card3 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card3[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card3 or not.
System.out.print("Do card#3 is having Your Birthday (Y/N):");
ch3 = sc.next(".").charAt(0);
//If the day is in card 3,add the first row first column element to sum
if(ch3=='Y' || ch3=='y')
sum+=card3[0][0];
//Displaying card4 using nested for loop
System.out.println(":: Card4 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
9. {
System.out.printf("%3d",card4[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card4 or not.
System.out.print("Do card#4 is having Your Birthday (Y/N):");
ch4 = sc.next(".").charAt(0);
//If the day is in card 4,add the first row first column element to sum
if(ch4=='Y' || ch4=='y')
sum+=card4[0][0];
//Displaying card5 using nested for loop
System.out.println(":: Card5 ::");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
System.out.printf("%3d",card5[i][j]);
}
System.out.println(" ");
}
//Prompting whether the day of birth is having in card5 or not.
System.out.print("Do card#5 is having Your Birthday (Y/N):");
ch5 = sc.next(".").charAt(0);
//If the day is in card 5,add the first row first column element to sum
if(ch5=='Y' || ch5=='y')
sum+=card5[0][0];
System.out.println("Your Birthday is "+sum);
System.out.print(" Do You want to continue? (y/n): ");
ch = sc.next(".").charAt(0);
10. System.out.println("________________________________");
}while(ch=='Y' || ch=='y');
}
}
_________________________________________________
Output:
:: Card1 ::
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
Do card#1 is having Your Birthday (Y/N):y
:: Card2 ::
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
Do card#2 is having Your Birthday (Y/N):y
:: Card3 ::
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
Do card#3 is having Your Birthday (Y/N):n
:: Card4 ::
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Do card#4 is having Your Birthday (Y/N):n
:: Card5 ::
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Do card#5 is having Your Birthday (Y/N):n
11. Your Birthday is 3
Do You want to continue? (y/n):
y
:: Card1 ::
1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
Do card#1 is having Your Birthday (Y/N):n
:: Card2 ::
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
Do card#2 is having Your Birthday (Y/N):y
:: Card3 ::
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
Do card#3 is having Your Birthday (Y/N):n
:: Card4 ::
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
Do card#4 is having Your Birthday (Y/N):n
:: Card5 ::
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
Do card#5 is having Your Birthday (Y/N):n
Your Birthday is 2
Do You want to continue? (y/n):
n
12. ______________________________________________________
The reason this works because we are having the numbers of first row first column of cards as 1
2 4 8 16.With these 5 numbers we can amke any day between 1 and 31.Based on the Birthday
present in the cards those corresponding first row first column of every card is getting added to
find the birthday of the user.
______________________________________________________Thank you