What`s wrong in my code?

/ Delete the last string and add it to the beginning of the list 1. Create a list of strings. 2. Read from keyboard 5 strings. Add these strings to the list. 3. Delete the last string and add it to the beginning of the list. Repeat this action 13 times. 4. Display to the screen contents of the list. Each value should be on a new line. Use a loop. /

import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList;

public class Solution { public static void main(String[] args) throws Exception { //add your code here ArrayList<string>list = new ArrayList<string>(); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); for(int i = 0; i < 5; i++) { String s = r.readLine(); list.add(s); } String lastChyslo = list.get(list.size() - 1); list.remove(list.size() - 1); list.set(0, lastChyslo);

        for(int j = 0; j < list.size(); j++)
    {
        System.out.println(list.get(j));
    }

}

}

asked 14 Feb, 12:02

voland's gravatar image

voland
1
accept rate: 0%


According to the condition // Repeat this action 13 times.

for(int i = 0; i < 13; i++) { String lastChyslo = list.get(list.size() - 1); list.remove(list.size() - 1); list.add(0, lastChyslo); }

link

answered 20 Mar, 14:37

devi's gravatar image

devi
1
accept rate: 0%

it works fine

(20 Mar, 14:41) devi
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:

×5
×1

Asked: 14 Feb, 12:02

Seen: 208 times

Last updated: 20 Mar, 14:41