Input:12-4-78==OUTPUT:12041978 //Input:9-4-78==OUTPUT:09041978
-
THIS IS MY CODE BUT IT IS NOT GIVING THE RIGHT OUTPUT
package main;
import java.util.*;public class Year_Conversion {
public static void main(String[] args) {
String s1;
System.out.println("Input string in the following format dd-mm-yy:");
Scanner sc=new Scanner(System.in) ;
s1=sc.next();
convertDate(s1);
}
public static String convertDate(String s1)
{
String ans = null;
String[] parts=s1.split("-");
int d=Integer.parseInt(parts[0]);
int m=Integer.parseInt(parts[1]);
int y=Integer.parseInt(parts[2]);
if(d<10)
{
ans=ans+"0"+d;
}
else
{
ans=ans+d;
}
if(m<10)
{
ans=ans+"0"+m;
}
else
{
ans=ans+m;
}
ans=ans+"19"+y;
return ans;
}
} -
THIS IS MY CODE BUT IT IS NOT GIVING THE RIGHT OUTPUT
package main;
import java.util.*;public class Year_Conversion {
public static void main(String[] args) {
String s1;
System.out.println("Input string in the following format dd-mm-yy:");
Scanner sc=new Scanner(System.in) ;
s1=sc.next();
convertDate(s1);
}
public static String convertDate(String s1)
{
String ans = null;
String[] parts=s1.split("-");
int d=Integer.parseInt(parts[0]);
int m=Integer.parseInt(parts[1]);
int y=Integer.parseInt(parts[2]);
if(d<10)
{
ans=ans+"0"+d;
}
else
{
ans=ans+d;
}
if(m<10)
{
ans=ans+"0"+m;
}
else
{
ans=ans+m;
}
ans=ans+"19"+y;
return ans;
}
}What output do you get? Rather than convert to integer to determine if you need to prefix a zero why not use strings length, if it is 1 you need a zero...
-
THIS IS MY CODE BUT IT IS NOT GIVING THE RIGHT OUTPUT
package main;
import java.util.*;public class Year_Conversion {
public static void main(String[] args) {
String s1;
System.out.println("Input string in the following format dd-mm-yy:");
Scanner sc=new Scanner(System.in) ;
s1=sc.next();
convertDate(s1);
}
public static String convertDate(String s1)
{
String ans = null;
String[] parts=s1.split("-");
int d=Integer.parseInt(parts[0]);
int m=Integer.parseInt(parts[1]);
int y=Integer.parseInt(parts[2]);
if(d<10)
{
ans=ans+"0"+d;
}
else
{
ans=ans+d;
}
if(m<10)
{
ans=ans+"0"+m;
}
else
{
ans=ans+m;
}
ans=ans+"19"+y;
return ans;
}
}- DON'T SHOUT! Typing in all capitals on the internet is considered shouting. Typing your entire message in capitals is rather rude. 2) If you want someone to help you get the "right output", then you need to tell us what the "right output" is. Show us several examples of what you type in, what the expected output is, and what the actual output is. Without that information, we can't help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
THIS IS MY CODE BUT IT IS NOT GIVING THE RIGHT OUTPUT
package main;
import java.util.*;public class Year_Conversion {
public static void main(String[] args) {
String s1;
System.out.println("Input string in the following format dd-mm-yy:");
Scanner sc=new Scanner(System.in) ;
s1=sc.next();
convertDate(s1);
}
public static String convertDate(String s1)
{
String ans = null;
String[] parts=s1.split("-");
int d=Integer.parseInt(parts[0]);
int m=Integer.parseInt(parts[1]);
int y=Integer.parseInt(parts[2]);
if(d<10)
{
ans=ans+"0"+d;
}
else
{
ans=ans+d;
}
if(m<10)
{
ans=ans+"0"+m;
}
else
{
ans=ans+m;
}
ans=ans+"19"+y;
return ans;
}
}