Java MCQ(may be option will be suffeld)
1 if syntax is incorrect
2 awk'BEGIN {FS=" "}{if($5=="Yes"){print $2,$4}}' product.txt
3 Display line 2 to 10 from file1
4 True (not got execueted as there is not BEGIN)
5 name="unix"
echo "Hello $name"
9 LENGTH()
10 SELECT *FROM Toddler Where NAME='A%'
14 ALTER TABLE table_name
ADD column_name datatype;
15 update Employee set designation=ITA where loaction is null
16 var carName="Honda City";
17 Object (type of var x={firstName:"TCS",lastName="ILP"};)
18 Number 16
19 Required
20 h6
21 on clikcking the "clickme ' linnk it will open google.com in parent frame
22 Background blue and font white
23 span
24 Jaguar
25 head
26 ArrayIndexOutOfBoundsException
27 package
28 easy to learn
29 False
30 365
1 if syntax is incorrect
2 awk'BEGIN {FS=" "}{if($5=="Yes"){print $2,$4}}' product.txt
3 Display line 2 to 10 from file1
4 True (not got execueted as there is not BEGIN)
5 name="unix"
echo "Hello $name"
9 LENGTH()
10 SELECT *FROM Toddler Where NAME='A%'
14 ALTER TABLE table_name
ADD column_name datatype;
15 update Employee set designation=ITA where loaction is null
16 var carName="Honda City";
17 Object (type of var x={firstName:"TCS",lastName="ILP"};)
18 Number 16
19 Required
20 h6
21 on clikcking the "clickme ' linnk it will open google.com in parent frame
22 Background blue and font white
23 span
24 Jaguar
25 head
26 ArrayIndexOutOfBoundsException
27 package
28 easy to learn
29 False
30 365
👍6
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
Stationery[] f=new Stationery[n];
for(int i=0;i<n;i++){
int id=sc.nextInt();
int qty=sc.nextInt();
sc.nextLine();
String name=sc.nextLine();
int price=sc.nextInt();
//sc.nextLine();
f[i]=new Stationery(id,qty,name,price);
}
int chid=sc.nextInt();
Stationery ans=findStationeryWithMaximumPrice(f);
if(ans!=null){
System.out.println("id-"+ans.id);
System.out.println("quantity-"+ans.qty);
System.out.println("name-"+ans.name);
System.out.println("price-"+ans.price);
}
else{
System.out.println("No Stationery found with mentioned attribute");
}
Stationery ans1=searchStationeryById(f, chid);
if(ans1!=null){
System.out.println("id-"+ans1.id);
System.out.println("quantity-"+ans1.qty);
System.out.println("name-"+ans1.name);
System.out.println("price-"+ans1.price);
}
else{
System.out.println("No Stationery found with mentioned attribute");
}
}
public static Stationery findStationeryWithMaximumPrice(Stationery[] a)
{
Stationery ans=null;
if(a.length==0)return null;
int l=a.length;
int maxi=a[0].price;
for(int i=0;i<l;i++){
if((a[i].price)>maxi){
maxi=a[i].price;
ans=a[i];
}
}
return ans;
}
public static Stationery searchStationeryById(Stationery[] a,int id1)
{
Stationery ans1=null;
for(int i=0;i<a.length;i++){
if(a[i].id==id1){
ans1=a[i];
}
}
return ans1;
}
}
class Stationery {
int id;
int qty;
String name;
int price;
Stationery(int id,int qty,String name,int price){
this.id=id;
this.qty=qty;
this.name=name;
this.price=price;
}
}
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
Stationery[] f=new Stationery[n];
for(int i=0;i<n;i++){
int id=sc.nextInt();
int qty=sc.nextInt();
sc.nextLine();
String name=sc.nextLine();
int price=sc.nextInt();
//sc.nextLine();
f[i]=new Stationery(id,qty,name,price);
}
int chid=sc.nextInt();
Stationery ans=findStationeryWithMaximumPrice(f);
if(ans!=null){
System.out.println("id-"+ans.id);
System.out.println("quantity-"+ans.qty);
System.out.println("name-"+ans.name);
System.out.println("price-"+ans.price);
}
else{
System.out.println("No Stationery found with mentioned attribute");
}
Stationery ans1=searchStationeryById(f, chid);
if(ans1!=null){
System.out.println("id-"+ans1.id);
System.out.println("quantity-"+ans1.qty);
System.out.println("name-"+ans1.name);
System.out.println("price-"+ans1.price);
}
else{
System.out.println("No Stationery found with mentioned attribute");
}
}
public static Stationery findStationeryWithMaximumPrice(Stationery[] a)
{
Stationery ans=null;
if(a.length==0)return null;
int l=a.length;
int maxi=a[0].price;
for(int i=0;i<l;i++){
if((a[i].price)>maxi){
maxi=a[i].price;
ans=a[i];
}
}
return ans;
}
public static Stationery searchStationeryById(Stationery[] a,int id1)
{
Stationery ans1=null;
for(int i=0;i<a.length;i++){
if(a[i].id==id1){
ans1=a[i];
}
}
return ans1;
}
}
class Stationery {
int id;
int qty;
String name;
int price;
Stationery(int id,int qty,String name,int price){
this.id=id;
this.qty=qty;
this.name=name;
this.price=price;
}
}
👍3