You are on page 1of 4

1)

import java.util.*;
import java.io.*;
public class Solution {

public static void main(String[] args) {


Scanner scan = new Scanner(System.in);

int i = scan.nextInt();
double j = scan.nextDouble();
scan.nextLine();
String k = scan.nextLine();

System.out.println("String: " + k);


System.out.println("Double: " + j);
System.out.println("Int: " + i);

}
}

<input>

10
3.14
hello world

<output>
hello world
3.14
10

2)

condition---

If n is odd, print Weird


If n is even and in the inclusive range of 2 to 5, print Not Weird
If n is even and in the inclusive range of 6 to 20, print Weird
If n is even and greater than 20, print Not Weird

import java.util.*;

public class Solution {

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {


int N = scanner.nextInt();

if( N >=1 && N <= 100 ){

if(N == 2 || N == 4 ){
System.out.print("Not Weird");
}
else if( N % 2 == 0 && N > 20)
{
System.out.print("Not Weird");
}
else{
System.out.print("Weird");
}
}
}}

<input>
24
<output>
Not Weird

3)

import java.util.Scanner;

public class Solution {

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("================================");
for(int i=0;i<3;i++){
String s1=sc.next();
int x =sc.nextInt();

String s = String.format("%-15s%03d",s1,x);

System.out.println(s);

}
System.out.println("================================");

}
}

<input>

java 100
cpp 65
python 50

<output>
================================
java 100
cpp 065
python 050
================================
4)

import java.util.*;
public class Solution {

private static final Scanner scanner = new Scanner(System.in);

public static void main(String[] args) {


int N = scanner.nextInt();
int i;

int ans;
for ( i=1; i<=10;i++){
ans = N * i;
System.out.println(N +" x "+i+" = "+ans);

}}
}
<input>
2

<output>

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

5)

import java.util.*;

public class Number {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("enter max number you want to find prime number");
int n = s.nextInt();

if(n>1) {

for(int i = 2;i <=n; i++) {

if(i == 2 || i == 3 || i == 5) {

System.out.println(i);

}else if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0) {
continue;

}else {
System.out.println(i);
}
}

}
}
}

<input>
10

<output>
2
3
5
7

You might also like