Advertisement
StefanTobler

Lesson 22 Activity 1

Oct 22nd, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. /*
  2.  * Lesson 22 Coding Activity 1
  3.  * Write the code to take a String and print it with one letter per line.
  4.  
  5.   Sample run:
  6.  
  7.   Enter a string:
  8.   bought
  9.   b
  10.   o
  11.   u
  12.   g
  13.   h
  14.   t
  15.  
  16. */
  17.  
  18. import java.util.Scanner;
  19. import java.lang.Math;
  20.  
  21. class Lesson_22_Activity_One {
  22.     public static void main(String[] args)
  23.      {
  24.       Scanner scan = new Scanner(System.in);
  25.       System.out.println("Enter a string:");
  26.       String x = scan.nextLine();
  27.       System.out.println(x);
  28.       int len = x.length();
  29.       int b = x.length();
  30.       System.out.println(b);
  31.       while (b > 0)
  32.       {
  33.        System.out.println(x.charAt(len-b));
  34.        b--;
  35.       }
  36.      
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement