Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lesson 22 Coding Activity 2
- * Write the code to take a String and print it diagonally.
- Sample run:
- Enter a string:
- bought
- b
- o
- u
- g
- h
- t
- Use a tab character for every four spaces in the sample.
- Hint: You may need more than one loop.
- */
- import java.util.Scanner;
- import java.lang.Math;
- class Lesson_22_Activity_Two {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter a string:");
- String x = scan.nextLine();
- System.out.println(x);
- int len = x.length();
- int b = x.length();
- int y = x.length();
- while (b > 0)
- {
- while (y != len)
- {
- System.out.print("\t");
- y++;
- }
- System.out.println(x.charAt(len-b));
- b--;
- y = b;
- }
- }
- }
Add Comment
Please, Sign In to add comment