0% found this document useful (0 votes)
89 views10 pages

Day 17 Criteria: Sno Answer

This document contains 5 coding questions/problems with sample inputs and outputs. The problems involve generating numeric series, printing alphabet patterns, numeric patterns, and identifying secret members based on a passcode. The solutions provided utilize basic Java concepts like loops, conditionals, strings, arrays, input/output etc. to solve the given problems.

Uploaded by

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

Day 17 Criteria: Sno Answer

This document contains 5 coding questions/problems with sample inputs and outputs. The problems involve generating numeric series, printing alphabet patterns, numeric patterns, and identifying secret members based on a passcode. The solutions provided utilize basic Java concepts like loops, conditionals, strings, arrays, input/output etc. to solve the given problems.

Uploaded by

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

Sno Question Answer

1 Day 17 Criteria
import java.util.*;
Day 17 Criteria
Write a program to generate the below series: import java.io.*;
0,2,3,5,8,10,15,17,24,26,...
Input Format:
public class Main {
Input consists of a single integer that corresponds to n. public static void main(String[] args) {
Output Format:
The output consists of the terms in the series separated by a blank space. //fill your code here
Sample Input 1: Scanner sc=new Scanner(System.in);
11
Sample Output 1: int count=0, i=0, j=2, k=1, l=1;
0 2 3 5 8 10 15 17 24 26 35
Sample Input 2: for (int n=sc.nextInt(); count < n ;count ++){
20 int temp;
Sample Output 2:
0 2 3 5 8 10 15 17 24 26 35 37 48 50 63 65 80 82 99 101 if(count % 2==0)temp=count !=0?i=i+(k=k+2):i;
else temp = j= count !=1 ? j+(l=l+2):j;
System.out.printf("%d\t",temp);
}
2 Alphabet Patterns 4
Write a program to print the given pattern.
import java.util.*;
Input Format: public class Main {
Input consists of a single integer which corresponds to the number of rows..
Output Format:
Refer sample output.
Sample Input:
public static void main(String[] args) {
5 int i,j,n;
Sample Output:
E Scanner s = new Scanner(System.in);
ED
EDC
n= s.nextInt();
EDCB for(i=n;i>=1;i--)
EDCBA
{for(j=n;j>=i;j--)
{System.out.print((char)(j+64));
}
System.out.println();
}
}

}
3 Pattern 3
Write a program to print the given pattern.
import java.util.*;
Input Format:Input consists of a single integer. public class Main {
Output Format:
Refer sample outputs. There is a trailing space at the end of each line. public static void main(String[] args) {
Sample Input:
5
Scanner sc = new Scanner(System.in);
Sample Output: int n = sc.nextInt();
54321
4321 for(int x=n;x>=1;x--)
321
21
{ for (int y=x;y>0;y--)
1 System.out.print(y + " ");
System.out.println();
}
}

}
4 Day 13 Criteria
import java.util.Scanner;
Write a program to generate the below series:
5,17,37,65,145, 197,….
public class Main {

public static void main(String[] args) {


Scanner sc =new Scanner(System.in);
int n=sc.nextInt();
int a=2;
Input Format: for(int i=1;i<=n;i++)
Input consists of a single integer which corresponds to n. {
Output Format:
System.out.println(((a*a)+1)+" ");
Output consists of the terms in the series separated by a blank space.
Sample Input 1:
a=2*(i+1);
6 }
Sample Output 1:
5 17 37 65 101 145 }
Sample Input 2:
}
15
Sample Output 2:
5 17 37 65 101 145 197 257 325 401 485 577 677 785 901

5 SECRET 7 import java.io.BufferedReader;


The Secret 7 is a secret investigation team consisting of 7 members. The team members meet once every fortnight. The Famous 5 is a rival import java.io.IOException;
gang and they try to steal secrets from secret seven. In each of their meets they decide a passcode for the next meet. The passcode they set is import java.io.InputStreamReader;
a 4 digit number with same numbers in the even places and odd places. Your friend is a part of the group and seeks your help to identify the
Secret 7 members. Can you help him out ??? public class Main {
Input format:
Input consists of an integer corresponding to the passcode entered by the member. public static void main(String[] args) throws NumberFormatException, IOException {
Output format: BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
The Output consists of the strings "Passcode matched. Hi Secret 7!!!” or “Sorry!!! passcode mismatched. Wrong identification.”. System.out.println("Passcode:");
Refer sample input and output for formatting specifications. int m=Integer.parseInt(bf.readLine());
[All text in bold corresponds to input and the rest corresponds to output.] Integer [] ma=new Integer[4];
for (int i =3; i >=0; i--) {
Sample Input and Output 1: ma[i]=m%10;
Passcode:
m=m/10;
1231 }
Sorry!!! passcode mismatched. Wrong identification.
if(ma[0]==ma[2]&& ma[1]==ma[3]) {
Sample Input and Output 2: System.out.println("Passcode matched. Hi Secret 7!!!");
Passcode: }else {
1010 System.out.println("Sorry!!! passcode mismatched. Wrong identification.");
Passcode matched. Hi Secret 7!!! }
}

}
6 GRADE import java.util.Scanner;
Write a program to determine the grade of the student in a particular subject. Refer to the table given below for grade public class Main {
details. public static void main(String[] args)
Marks scored Grade { Scanner sc=new Scanner(System.in);
100 S
[90,100) A System.out.println("Enter the marks");
[80,90) B double Marks=sc.nextDouble();
[70,80) C if(Marks==100)
[60,70) D { System.out.println("The student obtained a S grade");
[50,60) E }
<50 F
The interval [a,b) includes all numbers greater than or equal to a and less than b.
else if(Marks<100&&Marks>=90)
Input and Output Format: { System.out.println("The student obtained a A grade");
Input consists of a single integer that corresponds to the marks scored by the student. }
Print "Invalid Input" if it is not in the range 0 to 100. else if(Marks<90&&Marks>=80)
Refer sample input and output for formatting specifications. {
[All text in bold corresponds to input and the rest corresponds to output.]
System.out.println("The student obtained a B grade");
Sample Input and Output 1:
Enter the marks }
85 else if(Marks<80&&Marks>=70)
The student obtained a B grade {
Sample Input and Output 2: System.out.println("The student obtained a C grade");
Enter the marks 850 }
Invalid Input
else if(Marks<70&&Marks>=60)
{
System.out.println("The student obtained a D grade");
}
else if(Marks<60&&Marks>=50)
{
System.out.println("The student obtained a E grade");
}
else if(Marks<50&&Marks>=0)
{
System.out.println("The student obtained a F grade");
}
else
{
System.out.println("Invalid Input");
}

}
}
7
Pattern 1 import java.util.*;
Write a program to print the given pattern. public class Main {
Input Format:
Input consists of a single integer. public static void main(String[] args) {
Output Format: //fill your code here
Refer sample outputs. There is a trailing space at the end of each line.
Sample Input 1:
Scanner sc= new Scanner(System.in);
5 // System.out.println("Num of rows");
Sample Output 1: int rows =sc.nextInt();
12345
1234
123
//System.out.println("pattern is");
12
1
//int n=5;
Sample Input 2: for(int i=rows;i>=1;i--){
3 for(int j=1;j<=i;j++){
Sample Output 2:
123 System.out.print(j+ "");
12
1 }
System.out.println();
}
}
}
8
Palindromic Prize import java.util.Scanner;
A customer in the Personalised Gift Store is awarded a prize when their bill number is a 3-digit palindrome. public class Main {
Write a program for identifying the prize winners.
Input Format: public static void main(String[] args) {
Input consists of a number that corresponds to the bill number.
Scanner scan = new Scanner(System.in);
Output Format: int billNo = scan.nextInt();
The output consists of a string that is either 'yes' or 'no'. The output is 'yes' when the customer receives the prize and is 'no' if((billNo/100)==(billNo%10))
otherwise.
Sample Input 1: System.out.println("yes");
565 else
Sample Output 1: System.out.println("no");
yes scan.close();
Sample Input 2: }
568
Sample Output 2: }
no
Sample Input 3:
66
Sample Output 3:
no

9 Sorted Prize import java.util.Scanner;


A customer in the Personalised Gifts Store is awarded a prize when their bill number is a 3-digit number and all the 3 digits are in sorted order. (Examples ---> 379,
256, 973, 652, 225, 522 ...]
public class Question9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int arr[] = new int[3];
for(int i=0; i<3;i++)
{
arr[i]=m%10;
m = m/10;
}
if(arr[0]>arr[1] && arr[1]>arr[2])
System.out.println("yes");
Help Gita in identifying the prize winners. else if(arr[2]>arr[1] && arr[1]>arr[0])
Input Format:
Input consists of a number which corresponds to the bill number. System.out.println("yes");
Output Format: else
The output consists of a string that is either 'yes' or 'no'. The output is yes when the customer receives the prize
and is no otherwise. System.out.println("no");
Sample Input 1: }
565
Sample Output 1: }
No
Sample Input 2:
620
Sample Output 2:
yes
Sample Input 3:
66
Sample Output 3:
noTop of Form
Bottom of Form

10 import java.util.Scanner;
Series-II
Write a program to generate the below series: public class Main {
4,32,128,256, ….n public static void main(String[] args) {
Input and Output Format: Scanner sc=new Scanner(System.in);
The first line is the input consists of a single integer that corresponds to n. int m=4;
The output consists of the series 4,32,128,…..n separated by a space. int multiple=8;
Sample Input 1: int n=sc.nextInt();
4 for(int i=0;i<n;i++)
Sample Output 1: {System.out.print(m+" ");
4 32 128 256
m=m*multiple;
Sample Input 2:
2 multiple=multiple/2;
Sample Output 2: }
4 32 }
Sample Input 3: }
6
Sample Output 3:
4 32 128 256 256 0
11
Alphabet Pattern 1 import java.util.*;
public class Main {
Write a program to print the given pattern.
public static void main(String[] args) {
Input and Output Format: int i,j;
Input consists of a single integer that corresponds to the number of rows,n.
The output is the alphabet pattern for the given input,n. Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
Sample Input 1:
5
Sample Output 1: for(i=1;i<=n;i++)
A {
AB
ABC for(j=1;j<=i;j++)
ABCD {
ABCDE
System.out.print((char)(j+64));
Sample Input 2: }
7
System.out.println("");
Sample Output 2:
A }
AB }
ABC
ABCD
ABCDE }
ABCDEF
ABCDEFG

12
COUNTING
Write a program to count the vowels, consonants, digits, and white spaces in a string.

Input and Output Format :

Input consists of a string. Assume the maximum length of the string is 200.
The characters in the string can contain both uppercase and lowercase.
Refer sample input and output for formatting specifications.

[All text in bold corresponds to the input and the rest corresponds to output.]

Sample Input and Output 1 :


Enter a line of string
This program is very easy 2 complete
Vowels: 10
Consonants: 19
Digits: 1
White spaces: 6

Sample Input and Output 2 :

Enter a line of string


WelcomE
Vowels: 3
Consonants: 4
Digits: 0
White spaces: 0

13
Prime
Write a program to find whether a given number is prime or not.

Input Format:
Input consists of a single integer.

Output Format:
The output should display whether the input is “Prime” or “Not prime”.
Refer sample input and output for formatting specifications.

Sample Input 1:
13
Sample Output1:
Prime

Sample Input 2:
33
Sample Output2:
Not prime

14 P1 - Armstrong Number import java.util.*;

public class Main {


An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the
number itself. For example, 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371. public static void main(String[] args) {
Write a program to find whether a given 3-digit number is an Armstrong number or not. Scanner s = new Scanner(System.in);
Input Format: int n = s.nextInt();
Input consists of a single integer. int c=0,a,temp;
Output Format: temp = n;
Refer sample output for details. while (n>0)
Sample Input 1: {a = n%10;
n = n/10;
153 c = c + (a*a*a);
Sample Output 1: }
if (temp == c)
Armstrong Number System.out.println("Armstrong Number");
Sample Input 2: else
System.out.println("Not An Armstrong Number");
101
}
Sample Output 2:
}
Not An Armstrong Number

15 Lucky Customer Award import java.util.Scanner;


Every day few of the customers are given a lucky gift. Lucky gift is given to a customer when his / her bill number ends public class Main {
with the last digit of that day number or when the bill number is a multiple of the day number.Can you help Gita in deciding
whether a customer gets the lucky gift or not?
Input Format: public static void main(String[] args) {
Input consists of 2 integers that correspond to the day number in today's date and the bill number.
// TODO Auto-generated method stub
Output Format: Scanner sc=new Scanner(System.in);
Output is either 'yes' or 'no'. Output is yes when the customer gets the lucky gift and is no otherwise.
int date=sc.nextInt();
int billno=sc.nextInt();
Sample Input 1:
5 int r=billno%10;
45 int dr=date%10;
Sample Output 1:
yes if(r==dr||billno%date==0)
{
Sample Input 2: System.out.println("yes");
14 }
34
Sample Output 2: else {
yes System.out.println("no");
}
Sample Input 3: }
5
44
Sample Output 3: }
no

16
Day 11 Criteria import java.util.*;
Write a program to generate the below series: public class Main {
24,60,120,210,…
Input Format:
Input consists of a single integer that corresponds to n. public static void main(String[] args) {
Output Format:
The output consists of the terms in the series separated by a blank space.
Scanner sc=new Scanner(System.in);
Sample Input 1: int n=sc.nextInt();
5 for(int i=2;i<=n+1;i++)
Sample Output 1:
24 60 120 210 336 {
int j=i+1;
Sample Input 2:
10 int k=i+2;
Sample Output 2: System.out.print(i*j*k+ " ");
24 60 120 210 336 504 720 990 1320 1716
j=0;
k=0;
}
}
}
17 P3 – Number series import java.util.Scanner;
Write a program to print the series ---- 1,3,6,10,15 ….. upto ‘n’ terms.
Input Format: public class Main {
Input consists of a single integer.
Output Format: public static void main(String[] args) {
Refer sample output for details.
Sample Input: Scanner sc = new Scanner(System.in);
6 int terms=sc.nextInt();
Sample Output: int n=1;
1 3 6 10 15 21
int m=2;
System.out.print(n+" ");
for(int i=1;i<terms;i++)
{
n=n+m;
System.out.print(n+" ");
m++;
}
//Fill your code here
}
}
18
Alphabet Pattern 9 import java.util.Scanner;
Write a program to print the given pattern.

Input Format: public class Main {


Input consists of a single integer which corresponds to the number of rows..

Output Format: public static void main(String[] args) {


Refer sample output. Scanner scan=new Scanner(System.in);
char c = 'A';
Sample Input:
5 int rows =scan.nextInt();
for (int i = 0; i< rows; i++) {
Sample Output:
A for (int j = 0; j <= i; j++) {
BB System.out.print((char)(c+i));
CCC
DDDD
}
EEEEE System.out.println();
}
scan.close();
}
}
19
20

You might also like