Skip to document

393097050-Mettl-Solutions

Course

Microfluidics (BITS F421T)

5 Documents
Students shared 5 documents in this course
Academic year: 2021/2022
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
Technische Universiteit Delft

Comments

Please sign in or register to post comments.

Preview text

WTN METTL SOLUTIONS

Question 1: Is Even? Test link: tests.mettl/authenticateKey/2bd025dc import java.; import java.; // Read only region start class UserMainCode { public int isEven(int input1){ // Read only region end // Write code here... if(input1%2==0) return 2; else return 1; } }

Question 2: Is odd? Test link: tests.mettl/authenticateKey/dbdac2a import java.; import java.; // Read only region start class UserMainCode { public int isOdd(int input1){

if(input1%2!=0) return 2; else return 1; } }

Question 3: Return last digit of the given number Test link: tests.mettl/authenticateKey/454f012b import java.; import java.;

// Read only region start class UserMainCode {

public int lastDigitOf(int input1){ // Read only region end

int r=0; if(l==1) return -1; else { while(input1>0) { r=input1%10; c++; input1/=10; if(c==2) break; } return r; } } } ============================================================================== Question 5: Sum of last digits of two given numbers. Test link: tests.mettl/authenticateKey/783a1fcf import java.; import java.; class UserMainCode { public int addLastDigits(int input1,int input2){ if(input1<0) input1=(-1)*input1; if(input2<0) input2=(-1)*input2;

return (input1%10)+(input2%10); } } ==================================================================

Question 6 : Is N an exact multiple of M? Test link: tests.mettl/authenticateKey/36c4ef import java.; import java.;

// Read only region start class UserMainCode {

public int isMultiple(int input1,int input2){ // Read only region end // Write code here... int val=0; if(input1==0 || input2==0) val=3; else if((input1%input2)!=0) val=1; else val=2; return val; } }

if(input5%2==0) cnt++;

return cnt; }

Question 8 : Of given 5 numbers, how many are odd? Test link: tests.mettl/authenticateKey/67147bd import java.; import java.;

// Read only region start class UserMainCode { public int countEvens(int input1,int input2,int input3,int input4,int input5){ // Read only region end int cnt=0; if(input1<0) input1=(-1)*input1; if(input2<0) input2=(-1)*input2; if(input3<0) input3=(-1)*input3;

if(input4<0) input4=(-1)*input4; if(input5<0) input5=(-1)*input5; if(input1%2!=0) cnt++; if(input2%2!=0) cnt++; if(input3%2!=0) cnt++; if(input4%2!=0) cnt++; if(input5%2!=0) cnt++; return cnt; } }

Question 9 : Of 5 numbers, how many are even or odd? Test link: tests.mettl/authenticateKey/607636d import java.; import java.;

// Read only region start

if(input4%2==0) cnt++; if(input5%2==0) cnt++; } return cnt;

} }

Question 10: Is Prime? Test link : tests.mettl/authenticateKey/b1efaa3d

import java.; import java.;

// Read only region start class UserMainCode {

public int isPrime(int input1){

// Read only region end int cnt=0; for(int i=1;i<=input1;i++){ if(input1%i==0) cnt++; } if(cnt==2) return 2; else return 1;

} }

}

}

------------------------------------------------------------------------------------------------

------------------------------

(12)---->nth FIBONACCI

INPUT:
OUTPUT:2(0,1,1,2)

SOLUTION:

import java.*;
import java.*;

// Read only region start
class UserMainCode
{

public long nthFibonacci(int input1){
// Read only region end
int a=0;
int b=1;
int c=0;
int d=3;
while(d<=input1){


c=a+b;
a=b;
b=c;
d++;
}
return c;
}
}
------------------------------------------------------------------------------------------------
-------------------------------
(13)----->Nth PRIME:

INPUT: OUTPUT:

SOLUTION:

import java.; import java.;

// Read only region start class UserMainCode {

public int NthPrime(int input1){

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

INPUT:2 20

OUTPUT:8(2,3,5,7,11,13,17,19)

SOLUTION:

import java.; import java.;

// Read only region start class UserMainCode {

public int countPrimesInRange(int input1,int input2){ // Read only region end int k=2; int d=input1,i,c=0; int p=0; int cou=0; while(d<=input2){ for(i=2;i<d;i++){ if(d%i==0){ c++; }

}

if(c==0){ cou++; System.out(d); } d++; c=0; } return cou;

} }



(15)----->ALL DIGITS COUNT:

INPUT:
OUTPUT:

SOLUTION:

import java.*;
import java.*;


import java.*;
import java.*;

// Read only region start
class UserMainCode
{

public int uniqueDigitsCount(int input1){
// Read only region end
int c=0,r,i;
int h[]=new int[10];
while(input1>0){
r=input1%10;
h[r]++;
input1=input1/10;
}
for(i=0;i<10;i++){
if(h[i]>0){
c++;
}
}
return c;
}
}


### ------------------------------------------------------------------------------------------------

### -----------------------------------------

### (17)------>NON-REPEATED DIGITS COUNT:

### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### INPUT:

### OUTPUT:

### SOLUTION:

import java.*;
import java.*;

// Read only region start
class UserMainCode
{

public int nonRepeatDigitsCount(int input1){
// Read only region end

int c=0,r,i;
int h[]=new int[10];
while(input1>0){
r=input1%10;
h[r]++;
input1=input1/10;

Was this document helpful?

393097050-Mettl-Solutions

Course: Microfluidics (BITS F421T)

5 Documents
Students shared 5 documents in this course
Was this document helpful?
WTN METTL SOLUTIONS
Question 1: Is Even?
Test link: https://tests.mettl.com/authenticateKey/2bd025dc
import java.io.*;
import java.util.*;
// Read only region start
class UserMainCode
{
public int isEven(int input1){
// Read only region end
// Write code here...
if(input1%2==0) return 2;
else return 1;
}
}
Question 2: Is odd?
Test link: https://tests.mettl.com/authenticateKey/dbdac2a9
import java.io.*;
import java.util.*;
// Read only region start
class UserMainCode
{
public int isOdd(int input1){