java long 회전 String+Codeforces 110 A 사례

long 회전 String 에서 자주 사용 하 는 두 가지 방법:

long n=scanner.nextLong();
String s=Long.toString(n);//     
String s=String.valueOf(n);//     
코드 인 스 턴 스(codeforces 110 A):

import java.util.Scanner; 
public class Main {
 
  public static void main(String[] args) {
    // write your code here
    Scanner scanner=new Scanner(System.in);
    long n=scanner.nextLong();
    //String s=Long.toString(n);//     
    String s=String.valueOf(n);//     
    int count=0;
    for(int i=0;i<s.length();i++){
      if(s.charAt(i)=='4'||s.charAt(i)=='7'){
        count++;
      }
    }
    if(count==4||count==7){
      System.out.println("YES");
    }else {
      System.out.println("NO");
    }
  }
}
추가 지식:자바 string 형식 과 long 형식 간 의 전환 및 현재 시간 획득
1.현재 시간 가 져 오기

//       
 public static String get(){
 Date d=new Date();
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 String time=sim.format(d);
 System.out.println(time);
 return time;
 }
2.문자열 형식의 시간 을 long 형식 으로 변환 합 니 다.

public static long pare(String time){
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 long s=0;
 try {
  s=sim.parse(time).getTime();
 } catch (ParseException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return s;
 }
3.롱 타 입의 시간 을 String 타 입 으로 변경

public static String topare(long l){
 Date date = new Date(l);
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 String time=sim.format(date);
 return time;
 }
밤 한 톨
현재 시간 과 30 분 전의 시간 가 져 오기

package cn.com.tools; 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class GetTime {
//       
 public static String get(){
 Date d=new Date();
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 String time=sim.format(d);
 System.out.println(time);
 return time;
 }
//           
 public static void main(String[] args) {
 String t1=get();
 long t0=pare(t1);
 long t2=t0-1800000;
 // long     string  
 String tt=topare(t2);
 System.out.println(tt);
 
 }
//            long  
 public static long pare(String time){
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 long s=0;
 try {
  s=sim.parse(time).getTime();
 } catch (ParseException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return s;
 }
 // long       String  
 public static String topare(long l){
 Date date = new Date(l);
 SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 String time=sim.format(date);
 return time;
 }
}
이상 의 자바 롱 스 트 링+Codeforces 110 A 사례 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.참고 하 시기 바 랍 니 다.여러분 들 도 많이 응원 해 주시 기 바 랍 니 다.

좋은 웹페이지 즐겨찾기