Leetcode
Try hard Java on hackerrank
Day1: Wellcome 2 java
public class Solution{
public static void main(String[] args){
System.out.println("Hello, World.");
System.out.println("Hello, Java.");
}
}
Day2: java stdin and stdout
import java.util.Scanner;
public class Solution{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int number1 = input.nextInt();
int number2 = input.nextInt();
int number3 = input.nextInt();
System.out.println(number1);
System.out.println(number2);
System.out.println(number3);
}
}
Day3: java if else
import java.util.Scanner;
public class Solution{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
if(n%2!=0){
System.out.println("Weird");
}else{
if(n>=6 && n<=20){
System.out.println("Weird");
}else{
System.out.println("Not Weird");
}
}
}
}
Day4: java-stdin-stdout
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 space = "";
int length = s1.length();
for(int j=15;j>length;j--){
space+=" ";
}
//space da duoc fix
if(x>9 && x<100){System.out.println(s1+space+"0"+x);}
else if(x%10==x){System.out.println(s1+space+"00"+x);}
else{System.out.println(s1+space+x);}
}
System.out.println("================================");
}
}
Nhận xét
Đăng nhận xét