import java.io.*;

/* My name's ‘Joe’... Write a program that reads from keyboard a string «name» and a date of birth (three numbers): y, m, d. The program should display to the screen: «My name's «name» I was born on d.m.y»

Example:
«My name's Joe
I was born on 15.2.1988

*/

public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); String name = reader.readLine(); String d = reader.readLine(); String m = reader.readLine(); String y = reader.readLine(); int day = Integer.parseInt(d); int month = Integer.parseInt(m); int year = Integer.parseInt(y); System.out.println("My name's "+name); System.out.print("I was born on "+ d +"."+ m +"." +y);

}

}

My output is correct.but still not pass testing. anyone can help?

This question is marked "community wiki".

asked 23 Apr '15, 15:46

Muhammad%20Abu%20Bakr%20Chaudhry's gravatar image

Muhammad Abu...
12
accept rate: 0%

edited 23 Apr '15, 15:49


    public class Solution 
    { 
        public static void main(String[] args) throws Exception 
        { 
            BufferedReader reader = new BufferedReader (new InputStreamReader (System.in)); 
            String name = reader.readLine(); 
            String d = reader.readLine(); 
            String m = reader.readLine(); 
            String y = reader.readLine(); 
            int day = Integer.parseInt(d); 
            int month = Integer.parseInt(m); 
            int year = Integer.parseInt(y);

         System.out.println("My name's "+name); 
                System.out.print("I was born on "+ d +"."+ m +"." +y);
    /*you are passing in the String variables but they wanted the int
    variables...just rename your variables so that the String ones take
    the longer name and the one character named ones are int*/
         }
  }
link

answered 26 Apr '15, 14:31

Once%20the%20King%20of%20Andorra's gravatar image

Once the Kin...
676
accept rate: 11%

and whats wrong with my code?

public class Solution

{ public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String name = reader.readLine();

    int d = Integer.valueOf(reader.readLine());
    int m = Integer.valueOf(reader.readLine());
    int y = Integer.valueOf(reader.readLine());

    System.out.println("My name's " + name);
    System.out.println("I was born on " + d + "." + m + "." + y);
}

}

link

answered 03 Aug '17, 07:59

adrs's gravatar image

adrs
32
accept rate: 0%

Read documentation:

http://docs.oracle.com/javase/8/docs/api/

public static Integer valueOf(String s) throws NumberFormatException Returns an Integer object holding the value of the specified String.

parseInt returns a primitive.

I think thats why your cod didnt pas the test.

PS thats how implementation of valueOf method looks like:

public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
  }
link

answered 03 Aug '17, 08:29

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 03 Aug '17, 08:34

Ahh ok thanks for that, but actually I've tried parseInt as well and it didn't pass. That's weird because output seems to be ok

public class Solution

{

public static void main(String[] args)   throws Exception

{

    BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));

    String name = reader.readLine();
    String day = reader.readLine();
    String month = reader.readLine();
    String year = reader.readLine();

    int d = Integer.parseInt(day);
    int m = Integer.parseInt(month);
    int y = Integer.parseInt(year);

    System.out.println("My name's " + name);
    System.out.print("I was born on " + d + "." + m + "." + y);
}

}

link

answered 03 Aug '17, 09:59

adrs's gravatar image

adrs
32
accept rate: 0%

Write a program that reads from keyboard a string «name» and a date of birth (three numbers): y, m, d.

Year first input.

Please guys, copy description as well (i know its in 1st post but i didnt look at it :P).

link

answered 03 Aug '17, 10:39

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 03 Aug '17, 10:41

Oo gosh, yeah it was that. I've made 28 attempts according to Intellj and didn't see that... Thanks for help!!

link

answered 03 Aug '17, 10:59

adrs's gravatar image

adrs
32
accept rate: 0%

BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); String name = read.readLine(); int d =Integer.parseInt(read.readLine());//add your code here int m =Integer.parseInt(read.readLine());//add your code here int y =Integer.parseInt(read.readLine()); System.out.println(("My name's ")+name);//add your code here System.out.println(("I was born on ")+y+"."+m+"."+d);

link

answered 04 Sep, 14:55

Vladymyr's gravatar image

Vladymyr
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×69
×5

Asked: 23 Apr '15, 15:46

Seen: 1,406 times

Last updated: 04 Sep, 14:55