package com.codegym.task.task07.task0727;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Changing functionality
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
list.add(s);
// if(s.length()%2==0)
// System.out.println(s+" "+s) ;
// else
// System.out.println(s+" "+s+" "+s) ;
}
// ArrayList<String> listUpperCase = new ArrayList<String>();
//for (int i = 0; i < list.size(); i++) {
// String s = list.get(i);
// listUpperCase.add(s.toUpperCase());
//System.out.println(list.get(i));
// }
for (int i = 0; i < list.size(); i++) {
int x= list.get(i).length();
if(x%2==0)
System.out.println(list.get(i)+""+list.get(i));
else
System.out.println(list.get(i)+""+list.get(i)+""+list.get(i));
}
}
}
what's wrong?the code result always null point exception...help please
Resolved
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
yz Backend Developer
9 April 2020, 14:32
dont use s.isEmpty;
and also when reading from bufferedReadrer use this technique;
String str = "";
while( ! (str = reader.readLine() ).equals("") ){
//loop breaks when reader reads empty string
and doesnt continue but str will be last thing reader red here is "";
}
0
Hendra
10 April 2020, 03:29
thanks zy..this really help
0
yz Backend Developer
10 April 2020, 08:28
you are welcome
0