Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. input String S, output the length of String S String s = sc.nextLine();
  2. System.out.println(s.length());
  3. input String A. output YES if A equals to "Happy" String a = sc.nextLine();
  4. if(a.equals("Happy")){System.out.println("yes");}
  5. input String B, output the amount of letter "A" inside String B using for loop
  6. int e = 0;
  7. String f = sc.nextLine();
  8. for(int i=0; i<f.length(); i++){
  9. if(f.equals("A")){e++;}
  10. }System.out.println(e);
  11. input String C, output the amount of "7" inside String C using replace
  12. String C = sc.nextLine();
  13. String c2 = C.replaceAll("7", "");
  14. System.out.println(C.length()-c2.length());
  15.  
  16. Using for loop to output "===" 100 times
  17. for(int i=0; i<100; i++){
  18. System.out.println("===");
  19. }
  20. Using for loop to output "++" 5 times
  21. for(int i=0; i<5; i++){
  22. System.out.println("++");
  23. }
  24. Using for loop to output "HI" 11 times
  25. for(int i=0; i<11; i++){
  26. System.out.println("HI");
  27. }
  28. Using for loop to output "Yummy" 10 times
  29. for(int i=0; i<10; i++){
  30. System.out.println("Yummy");
  31. }
  32. Using for loop to output "Bruce" 23 times
  33. for(int i=0; i<23; i++){
  34. System.out.println("Bruce");
  35. }
  36. Using for loop to output 0 5 10 15 20 25 30
  37. for(int i=0; i<35; i+=5){
  38. System.out.println(i);
  39. }
  40. Using for loop to output 1 2 3 4 5
  41. for(int i=1; i<6; i++){
  42. System.out.println(i);
  43. }
  44. input String S
  45. Using for loop to output char one by one from String S forward
  46. Using for loop to output char one by one backward
  47. String w = sc.nextLine();
  48. for(int i=0; i<w.length(); i++){
  49. System.out.print(w.charAt(i));
  50. }System.out.println();
  51. for(int i=w.length()-1; i>=0; i--){
  52. System.out.print(w.charAt(i));
  53. }
  54. A is 1 3 5 7
  55. B is 2 4 6 8
  56. Using nested for loop to output A and B's combination
  57. int[] AA = {1, 3, 5, 7};
  58. int[] Ab = {2, 4, 6, 8};
  59. for(int i=0; i<16; i++){
  60. System.out.println(AA[i]+" "+Ab[i]);
  61. }
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement