Day 17 Criteria: Sno Answer
Day 17 Criteria: Sno 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 {
}
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
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 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.]
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
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.