java long转String +Codeforces110A案例

网友投稿 259 2022-11-20


java long转String +Codeforces110A案例

long转String常用的两种方法:

long n=scanner.nextLong();

String s=Long.toString(n);//第一种方法

String s=String.valueOf(n);//第二种方法

代码实例(codeforces 110A):

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

if(s.charAt(i)=='4'||s.charAt(i)=='7'){

count++;

}

}

if(count==4||count==7){

System.out.println("YES");

}else {

System.out.println("NO");

}

}

}

补充知识:java 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(qqftXIwd);

System.out.println(time);

return time;

}

2、把字符串类型的时间转换为long类型

public static long pare(String tihttp://me){

SimpleDateFormat sim=new SimpleDateFohttp://rmat("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、把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;

}

一个小栗子

获取当前时间和半个小时之前的时间

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;

}http://

}

if(s.charAt(i)=='4'||s.charAt(i)=='7'){

count++;

}

}

if(count==4||count==7){

System.out.println("YES");

}else {

System.out.println("NO");

}

}

}

补充知识:java 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(qqftXIwd);

System.out.println(time);

return time;

}

2、把字符串类型的时间转换为long类型

public static long pare(String tihttp://me){

SimpleDateFormat sim=new SimpleDateFohttp://rmat("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、把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;

}

一个小栗子

获取当前时间和半个小时之前的时间

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;

}http://

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:api客户端(API 平台)
下一篇:测试用例表(测试用例表怎么做)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~