StefanTobler

Lesson 22 Activity 2

Oct 22nd, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /*
  2.  * Lesson 22 Coding Activity 2
  3.  * Write the code to take a String and print it diagonally.
  4.  
  5.   Sample run:
  6.  
  7.   Enter a string:
  8.   bought
  9.   b
  10.       o
  11.           u
  12.               g
  13.                   h
  14.                       t
  15.   Use a tab character for every four spaces in the sample.
  16.  
  17.   Hint: You may need more than one loop.
  18.  
  19. */
  20.  
  21. import java.util.Scanner;
  22. import java.lang.Math;
  23.  
  24. class Lesson_22_Activity_Two {
  25.     public static void main(String[] args)
  26.      {
  27.       Scanner scan = new Scanner(System.in);
  28.       System.out.println("Enter a string:");
  29.       String x = scan.nextLine();
  30.       System.out.println(x);
  31.       int len = x.length();
  32.       int b = x.length();
  33.       int y = x.length();
  34.       while (b > 0)
  35.       {
  36.        while (y != len)
  37.        {
  38.          System.out.print("\t");
  39.          y++;
  40.        }
  41.        
  42.        System.out.println(x.charAt(len-b));
  43.        b--;
  44.        y = b;
  45.       }
  46. }
  47. }
Add Comment
Please, Sign In to add comment